Quantcast

Getting plots in Octave to show colors like Matlab.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
RT
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Getting plots in Octave to show colors like Matlab.

RT
I get two different plots using matlab 2013 and octave 4.0 see code below is there anyway to show the different colors in the plot like matlab shows using octave?


Input image of marbles.jpg: http://i.imgur.com/17S9PUK.jpg


pkg load image
rgbImage = imread('/tmp/marbles.jpg'););  % Load image Image of marbles.jpg: http://i.imgur.com/17S9PUK.jpg
hsvImage = rgb2hsv(rgbImage);         % Convert the image to HSV space
hPlane = 360.*hsvImage(:, :, 1);      % Get the hue plane scaled from 0 to 360

binEdges = 0:360;                 %# Edges of histogram bins
N = histc(hPlane(:),binEdges);    %# Bin the pixel hues from above
hBar = bar(binEdges(1:end-1),N(1:end-1),'histc');  %# Plot the histogram
set(hBar,'CData',1:360,...            %# Change the color of the bars using
         'CDataMapping','direct',...  %#   indexed color mapping (360 colors)
         'EdgeColor','none');         %#   and remove edge coloring
colormap(hsv(360));               %# Change to an HSV color map with 360 points
axis([0 360 0 max(N)]);           %# Change the axes limits
set(gca,'Color','k');             %# Change the axes background color
set(gcf,'Pos',[50 400 560 200]);  %# Change the figure size
xlabel('HSV hue (in degrees)');   %# Add an x label
ylabel('Bin counts');             %# Add a y label

Matlab 2013 what the Plot looks like
https://i.stack.imgur.com/mHIoc.png

But when I create the plot with Octave 4.0 I get
http://i.imgur.com/acubTY9.png

The main goal is to have the histogram colors be the same as the matlab plot.  How can I fix this?




_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting plots in Octave to show colors like Matlab.

NJank
On Apr 23, 2017 9:56 AM, "RT" <[hidden email]> wrote:
I get two different plots using matlab 2013 and octave 4.0 see code below is there anyway to show the different colors in the plot like matlab shows using octave?

don't have either in front of me to test, but can you step through and find the first point where things differ between the two? My guess is its something with colormap, but it could be at the set command or an incompatibility with one of those options, or on one of the redraws with the later commands, etc.

nickj

_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting plots in Octave to show colors like Matlab.

Hartmut
In reply to this post by RT
The CData property doesn't seem to be implemented in the Octave version of the bar command.

You could work around this by plotting all the single bars individually. And setting an individualy color of each individual bar. The following code runs for several seconds, but works generally fine for me (in Octave 4.2.1):

--- code ----
pkg load image
rgbImage = imread('marbles.jpg');  % Load image Image of marbles.jpg: http://i.imgur.com/17S9PUK.jpg
hsvImage = rgb2hsv(rgbImage);         % Convert the image to HSV space
hPlane = 360.*hsvImage(:, :, 1);      % Get the hue plane scaled from 0 to 360
binEdges = 0:360;                 %# Edges of histogram bins
N = histc(hPlane(:),binEdges);    %# Bin the pixel hues from above

C = colormap(hsv(360));  %# create an HSV color map with 360 points
stepsize = 10; % stepsize 1 runs for a while...

for n=binEdges(2:stepsize:end)   %# Plot the histogram, one bar each
    if (n==1), hold on, end
    h=bar(n,N(n));
    set(h,'FaceColor',C(n,:));   %# set the bar color individually
end

axis([0 360 0 max(N)]);           %# Change the axes limits
set(gca,'Color','k');             %# Change the axes background color
set(gcf,'Pos',[50 400 560 200]);  %# Change the figure size
xlabel('HSV hue (in degrees)');   %# Add an x label
ylabel('Bin counts');             %# Add a y label
--- code ---

By the way, Matlab seems to also have the same problems, when using a Matlab version of 2014b or newer, see [1]

I hope this helps.

    Hartmut


[1] https://de.mathworks.com/matlabcentral/answers/99092-how-do-i-define-colors-for-individual-bars-on-my-bar-graph-according-to-their-values-in-matlab

RT
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Getting plots in Octave to show colors like Matlab.

RT
In reply to this post by NJank
How would I step through plotting different colors?  It either plots a color or it doesn't. Am I missing something?

Thanks

On Sun, Apr 23, 2017 at 2:35 PM, Nicholas Jankowski <[hidden email]> wrote:
On Apr 23, 2017 9:56 AM, "RT" <[hidden email]> wrote:
I get two different plots using matlab 2013 and octave 4.0 see code below is there anyway to show the different colors in the plot like matlab shows using octave?

don't have either in front of me to test, but can you step through and find the first point where things differ between the two? My guess is its something with colormap, but it could be at the set command or an incompatibility with one of those options, or on one of the redraws with the later commands, etc.

nickj


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Loading...