In a image i want to store the location of yellow colour how can i do it ??

2 次查看(过去 30 天)
In this image I want to find location of yellow pixel

回答(2 个)

Sammit Jain
Sammit Jain 2018-5-21
Hi, since the image link isn't valid, I'll make the assumption that your task involves the following:
  1. Detecting the yellow color (the particular shade) correctly.
  2. Figuring out the location (of all the pixels that are yellow)
I'll also make the assumption that you aren't aware of the RGB range your particular shade of yellow lies in and first you would like to find out what the min,max values of R,G,B are for your color. In case you already know, then you can just skip the part and directly use the min,max values.
% Read the image
TestImg = imread('yourImage.jpg');
% Separating out the three R,G,B channels
TestImg_R = TestImg(:,:,1);
TestImg_G = TestImg(:,:,2);
TestImg_B = TestImg(:,:,3);
% Choosing some sample points for yellow using impixel
% This will open up a window, where you can select some points and press enter
chosen_points = impixel(TestImg);
% Setting the intervals accordingly
MAXC = max(chosen_points);
MINC = min(chosen_points);
r_max = MAXC(1) + 1;
r_min = MINC(1) - 1;
g_max = MAXC(2) + 1;
g_min = MINC(2) - 1;
b_max = MAXC(3) + 1;
b_min = MINC(3) - 1;
% Segmenting the image according to the intervals
OutImg = TestImg_R<r_max & TestImg_R>r_min & ...
TestImg_G<g_max & TestImg_G>g_min & ...
TestImg_B<b_max & TestImg_B>b_min;
% OutImg is now a binary image where all yellow pixels are white and everything else is black
% Check results in subplots
subplot(1,2,1);
imshow(TestImg);
subplot(1,2,2);
imshow(OutImg);
OutImg is exactly your location map of all the yellow pixels. It has 1's for all yellow pixels and 0's for everything else. You can now use the indices of 1's as locations of the yellow color in the image.
Here's a sample output for when I chose green colored pixels in my image:

Image Analyst
Image Analyst 2018-5-21
Try this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Get an image of where the pure yellow pixels are.
yellowMask = redChannel == 255 & greenChannel == 255 & blueChannel == 0;
% Get the (row, column) indexes of where the yellow pixels are.
[rows, columns] = find(yellowMask);
  4 个评论
Image Analyst
Image Analyst 2018-5-24
That's because your yellow is not pure yellow. You jepgged the image or anti-aliased the line so that the yellow is not pure yellow anymore.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by