-1

how to make an image(of 510*510) with red , green ,bue in upper row and cyan magenta and yellow in lower row in matlab with equal portion for all.

Rabeel
  • 311
  • 2
  • 6
  • 17

2 Answers2

2

Your question is a little vague, but I think I know what you are asking for. The hue channel of an HSV image is usually thought of as ranging from 0 to 360 degrees, since it is a cylindrical-coordinate representation of points in an RGB color model. However, the values of the hue channel are likely ranging from 0 to 1 for your image, which is what you get as output from the function RGB2HSV, if that's what you used to get your HSV map.

So, if you want to shift your hues by 120 degrees, you would have to shift your range by 1/3. In other words, values ranging from 0 to 1/3 should be changed to range from 1/3 to 2/3, assuming a positive shift of 120 degrees. You can achieve this with the REM function like so:

H = rem(H + 1/3, 1);

For a negative shift of 120 degrees, you can just apply an equivalent positive shift of 240 degrees, like so:

H = rem(H + 2/3, 1);
gnovice
  • 125,304
  • 15
  • 256
  • 359
  • +1 for the correct answer. Given the comment by @Rabeel, I suspect this may be a Matlab-for-beginner exercise about reordering an array, though. – Jonas Dec 27 '12 at 17:27
2

For a poor-man's version of @gnovice's answer, I suggest simply swapping the R,G, and B channels, as suggested by @JasonD

Say you have a n-by-m-by-3 RGB image stored in an array img. Then, you shift the channels as follows

shiftedImg = img(:,:,[2 3 1]);

or

shiftedImg = img(:,:,[3 1 2]);
Jonas
  • 74,690
  • 10
  • 137
  • 177
  • 2
    @Rabeel: my solution does not use builtin functions at all. Unless you count accessing array elements as a builtin function, in which case you won't be able to use Matlab at all. – Jonas Dec 27 '12 at 18:35