How to convert m-by-n-by-3 array to m-by-n?
4 views (last 30 days)
Show older comments
I am attempting to manually convert RGB values to HSI. I do not wish to use the rgb2hsv code included in MATLAB. Also, the hope is to manually recreate other color spaces I have found in research articles. Therefore, solving this problem would assist me immensly in those areas. Here is my code for the HUE component...
for i = 1:x
for j = 1:y
TH(i,j) = acos((((1/2).*((R(i,j) - G(i,j)) + (R(i,j) - B(i,j))))./(sqrt((R(i,j) - G(i,j)).^2 + ((R(i,j) - B(i,j)).*(G(i,j) - B(i,j)))))));
if B(i,j) <= G(i,j)
H(i,j) = TH(i,j);
elseif B(i,j) > G(i,j)
H(i,j) = ((2*pi) - TH(i,j));
end
end
end
...
The idea is that it will loop through each pixel and create THETA based on the formula, then assign a value to the HUE component image at that pixel based on the comparison of blue and green pixel values at that point (as shown in the code). My issue is that it does create H; however, H is an m-by-n-by-3 array, and i would like to have a m-by-n array. Any assistance in the matter would be appreciated and will serve as foundation for me to try an emulate other color spaces. Also if there is a cleaner way beside a for loop feel free to share.
THANK YOU
5 Comments
Walter Roberson
on 9 Feb 2020
H = TH;
Then skip the first test. The second test will overwrite all relevant parts of H.
If I recall correctly for computing hue you need tests involving different color channels not just B and G.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!