get RGB data from image

1 Ansicht (letzte 30 Tage)
Sorin Peña
Sorin Peña am 21 Apr. 2019
Kommentiert: Sorin Peña am 22 Apr. 2019
I was working on some code for a small assignment and can't seem to figure out why I can't get my bright vector to come out as [251,251,251] using this attached picture. The RGB values for the white section of the image are all 251.
picture = imread('ColorWheel.png')
[a,b,c] = size(picture);
bright = [0,0,0];
for y = 1:b
for x = 1:a
if picture(x,y,1) >= bright(1) && picture(x,y,2) >= bright(2) && picture(x,y,3) >= bright(3)
bright(1) = picture(x,y,1);
bright(2) = picture(x,y,2);
bright(3) = picture(x,y,3);
end
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 21 Apr. 2019
Your search encounters a pixel with components 5 6 255 . Your test for assigning a new brightness requires that **all* of the r g b components of the candidate be at least as big as the current bright . The pixels with value [251 251 251] fail on 251 >= 255 .
If the purpose of the assignment is to find the location with maximum brightness, then you need to take into account that brightness does not vary equally with the different color components. The green component has the most influence on brightness, followed by the red component, and the blue component has relatively little impact on brightness.
  7 Kommentare
Walter Roberson
Walter Roberson am 22 Apr. 2019
Those 1, 114, and 62 are the color values. That translates as red component being 1/255 times the maximum possible red, and green component being 114/255 times the maximum possible green, and blue component being 62/255 times the maximum possible blue.
Note that if what they actually mean is "whitest", then you would measure white content not by high value but rather by how equal the components are. As in
temp = sort([red(:), green(:), blue(:)], 2);
offwhiteness = reshape( sqrt((temp(:,2) - temp(:,1)).^2 + (temp(:,3) - temp(:,2)).^2), size(red));
and you would target offwhiteness of 0. A location that is [183, 183, 183] is exactly as "white" as a location that is [19, 19, 19], because in both cases there is an equal mixture of frequencies. The difference between them is brightness, which you say they are not actually looking for.
I would suggest to you that what they are really looking for is indeed brightness, but that you have misunderstood how brightness is calculated.
A pixel which is [128, 0, 0] is brighter than a pixel which is [0, 0, 255]. The first of those would work out as about 15% of maximum brightness, whereas the second of them would work out as about 11% of maximum brightness.
[97 0 0] is about as bright as [0 50 0] which is about as bright as [0 0 255]
Sorin Peña
Sorin Peña am 22 Apr. 2019
I understand now. Thank you all, my code is working well.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by