How to convert m-by-n-by-3 array to m-by-n?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2020-2-9
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.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!