Getting non-existent pixel values
4 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(2 个)
Image Analyst
2016-11-6
编辑:Image Analyst
2016-11-6
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.
Douglas Brenner
2016-11-6
编辑:Douglas Brenner
2016-11-6
1 个评论
Image Analyst
2016-11-7
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!