Borrar filtros
Borrar filtros

Trying to understand pixel value.

3 visualizaciones (últimos 30 días)
Arda Nova
Arda Nova el 24 de Feb. de 2019
Editada: Stephen23 el 24 de Feb. de 2019
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 comentarios
Arda Nova
Arda Nova el 24 de Feb. de 2019
I gave the example, I expected nothing to change.
Arda Nova
Arda Nova el 24 de Feb. de 2019
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?

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 24 de Feb. de 2019
Editada: Stephen23 el 24 de Feb. de 2019
"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 comentario
Arda Nova
Arda Nova el 24 de Feb. de 2019
Oh, I see now. I was turning EVERYTHİNG 12. It makes perfect sense now. Thank you.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by