How can I make diagram with different color at corner which fill triangle also also a scale bar showing range of value?

2 views (last 30 days)
How can I make a triangle with three end values are 3, 4 and 5 and within show color supposing first upper corner having value 3 will show blue, lower left corner having value 4 will show red and last lower right corner will show yellow and a scale at left/right side showing values from 3-5

Answers (1)

Image Analyst
Image Analyst on 25 Aug 2013
Not sure without working on it a bit but I'd say off the top of my head that it will probably involve roifill(). You might also have to use imline, linspace, and poly2mask.
  1 Comment
Image Analyst
Image Analyst on 25 Aug 2013
Why don't you start with this code:
width = 300; % pixels.
h = linspace(0, 0.7, width);
h = repmat(h, [width, 1]);
s = ones(width,width);
v = 0.95 * ones(width,width);
hsv = cat(3, h, s, v);
rgbImage = uint8(255*hsv2rgb(hsv));
rgbImage = imrotate(rgbImage, 135);
imshow(rgbImage)
axis on
You can also try making a grayscale ramp and use ind2rgb:
grayRamp = linspace(0, 255, width);
grayRamp = repmat(grayRamp, [width, 1]);
grayRamp = uint8(imrotate(grayRamp, -45));
% Convert to color
rgbImage = ind2rgb(grayRamp, jet(256));
figure;
imshow(rgbImage);
I've given you a good start. See if you can finish it using poly2mask() to create a triangular mask and then do an element by element multiplication to zero out outside of the triangle. A smart beginning engineer like you should be able to.

Sign in to comment.

Categories

Find more on Formatting and Annotation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!