Getting non-existent pixel values

1 visualizzazione (ultimi 30 giorni)
Douglas Brenner
Douglas Brenner il 6 Nov 2016
Commentato: Image Analyst il 7 Nov 2016
After the following code, an image is displayed. It is black, white and red. However, if I use hpimpixelinfo(2) on the image I only get 1's and 0's. How do I address the pixels and find out which are black, white, or red.
colors=['r'];
for k=1:length(B),
b = B{k};
cidx = mod(k,length(colors))+1;
plot(b(:,2), b(:,1),...
colors(cidx),'LineWidth',1);
end

Risposte (2)

Image Analyst
Image Analyst il 6 Nov 2016
Modificato: Image Analyst il 6 Nov 2016
Douglas, you need to use impixelinfo(), not hpimpixelinfo(). And you probably need to adjust where it is so you can see it. And you're passing in 2. I wouldn't do that. I'd just call it right after you call imshow() to make sure you're using it on the right figure.
hp = impixelinfo();
hp.Unit = 'normalized';
hp.Position = [0.01, 0.98, 0.2, 0.1]; % [xLeft, yTop, width, height]
If that doesn't show the pixel values in the upper left of your figure, then adjust the position.
To find red, see my Simple Color Detection app in my File Exchange where I do exactly that. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Basically you can extract the color planes
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
and, if your red is exactly (255,0,0) then find those pixels like this
redPixels = redChannel == 255 & greenChannel == 0 & blueChannel == 0;
imshow(redPixels);
To find black (0,0,0) pixels:
blackPixels = redChannel == 0 & greenChannel == 0 & blueChannel == 0;
imshow(blackPixels);
To find white (255,255,255) pixels:
whitePixels = redChannel == 255 & greenChannel == 255 & blueChannel == 255;
imshow(whitePixels);
If your colors are not pure computer graphics like that, then see my File Exchange app, or see the Color Thresholder on the Apps tab of the tool ribbon.
  1 Commento
Douglas Brenner
Douglas Brenner il 6 Nov 2016
I'll have to chew on this for awhile but should help. thanks.

Accedi per commentare.


Douglas Brenner
Douglas Brenner il 6 Nov 2016
Modificato: Douglas Brenner il 6 Nov 2016
Didn't work
Index exceeds matrix dimensions. Error in stddev (line 51) greenChannel = b(:, :, 2);
Is there a green plane? Only one color.
colors=['r']; for k=1:length(B), b = B{k}; cidx = mod(k,length(colors))+1; plot(b(:,2), b(:,1),... colors(cidx),'LineWidth',1)
And showing the red plane are commenting out the green and blue only shows 4 pixels
  1 Commento
Image Analyst
Image Analyst il 7 Nov 2016
Then you don't have a color image. Maybe you have an indexed image. Your code looks like there is not image, just a plot, but since the code doesn't run, because B is not defined, it's hard to tell what it will look like. Please post either code that runs, your image or screenshot, or both code and image.

Accedi per commentare.

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by