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!