Trying to understand pixel value.

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
original
untitlefasd.jpg
What I get.

7 件のコメント

GMD Baloch
GMD Baloch 2019 年 2 月 24 日
I don't understand your question what you want to do?
Do you want to alter the pixel values according to your desire or you want to do something else?
Stephen23
Stephen23 2019 年 2 月 24 日
編集済み: Stephen23 2019 年 2 月 24 日
"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."
Looking is not a very reliable way to test all values in an array. Better:
all(f(:)==12)
"What am I missing here?"
We don't know, because you did not upload a sample image and you did not explain what you expect to happen.
Arda Nova
Arda Nova 2019 年 2 月 24 日
Right now? I am trying to understand what exactly a pixel value does. Let's try this way, think about one pixel, blue, with a pixel value 12, and I change this value to 120. What should be the end result?
Arda Nova
Arda Nova 2019 年 2 月 24 日
Didn't know Stephen Cobeldick, thank you.
Stephen23
Stephen23 2019 年 2 月 24 日
編集済み: Stephen23 2019 年 2 月 24 日
"think about one pixel, blue, with a pixel value 12, and I change this value to 120. What should be the end result?"
If it is an RGB image (MxNx3) and you increase the blue channel from 12 to 120 then that pixel will be more blue. Of course when mixed with the other two color channels it might be perceived as another color, but it will still be more blue than it was before. It will increase the brightness of the pixel, and probably change the saturation (how depends on the values of the other two channels).
If it is a grayscale image (MxN) then that pixel will increase in brightness.
If is is an indexed image (MxN) then the color will change from color 12 to color 120, whatever they may be.
The MATLAB documentation has a good introduction to the three common bitmap image types:
Arda Nova
Arda Nova 2019 年 2 月 24 日
I gave the example, I expected nothing to change.
Arda Nova
Arda Nova 2019 年 2 月 24 日
That was what I thought too. I tried it to the 300x300 blue rgb picture (300x300x3), all I got was a grey picture. Why is that?

サインインしてコメントする。

 採用された回答

Stephen23
Stephen23 2019 年 2 月 24 日
編集済み: Stephen23 2019 年 2 月 24 日

0 投票

"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.

1 件のコメント

Arda Nova
Arda Nova 2019 年 2 月 24 日
Oh, I see now. I was turning EVERYTHİNG 12. It makes perfect sense now. Thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2019 年 2 月 24 日

編集済み:

2019 年 2 月 24 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by