Trying to understand pixel value.
6 ビュー (過去 30 日間)
古いコメントを表示
I am trying to understand pixel value, and trying to learn to alter it. But things act weird in matlab. Correct me if I am wrong but, pixel value is in a way amound of "light" a colour has. 0 means no light= black, 255 full light. Everything in between is something like, light blue dark blue and etc. So I googled "blue 300x300" and used this code:
clc;
clear all;
f = imread('C:\Users\*****\Desktop\images\sfaafsfas.jpg');
for i=0:255
f(f==i)=12;
end
imshow(f)
If I delete for loop, and look at the f value from workshot all the values of the pixel value (at least I think they are pixel values) all of them are 12. Then I add for loop, and check the values, still they are all 12, yet imshow shows me a grey image. It kinda makes sence, yet it does not too. Nothing chages but something changes. What am I missing here?
![sfaafsfas.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205608/sfaafsfas.jpeg)
original
![untitlefasd.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/205609/untitlefasd.jpeg)
What I get.
7 件のコメント
採用された回答
Stephen23
2019 年 2 月 24 日
編集済み: Stephen23
2019 年 2 月 24 日
"What am I missing here?"
You have ignored the fact that RGB images have three color channels, which in order to generate your "light-blue" square have quite different values. This is explained in the link that I gave you:
You also made a basic beginners mistake, which is to not actually look at your data thoroughly:
>> f = imread('sfaafsfas.jpg');
>> R = f(:,:,1);
>> G = f(:,:,2);
>> B = f(:,:,3);
>> unique(R(:))
ans = 12
>> unique(G(:))
ans = 186
>> unique(B(:))
ans = 255
The code I gave you earlier:
would have made it clear that your assumption that "all of them are 12" is incorrect: all of the blue channel values are 12, but none of the red or green channel values are. But in your loop you set all elements of the entire 3D array (i.e. all three color channels) to the same value (12), which for RGB by definition must be a gray color (if all channels have the same value then a pixel is gray).
"But things act weird in matlab. "
So far everything seems to be acting exactly as expected.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!