フィルターのクリア

How to find (x,y) coordinates of white pixel.

32 ビュー (過去 30 日間)
kanika bhalla
kanika bhalla 2021 年 7 月 1 日
コメント済み: Andrea 2023 年 3 月 22 日
I want to find (x,y) coordinates of the white pixel as marked in the attached Figure. I have tried some things but it is not giving me the exact solution. Can anyone please help me in this. I will be forever grateful for your help.
DDD=imread('binaryimage.png'); % Read an image
[rows, columns] = find(DDD',1,'last'); % Transpose 'DDD'
xTop = rows(1)
yTop = columns(1)
% Plot it
hold on;
plot(xTop, yTop, 'r+', 'MarkerSize', 10, 'LineWidth', 3);
hold off;

回答 (2 件)

Image Analyst
Image Analyst 2021 年 7 月 11 日
You can get all the coordinates of the white pixels using find().
[rows, columns] = find(binaryImage);
That gives yo a list of coordinates for every white pixel ignoring which blob it belongs to.
Or you can do it on a blob-by-blob basis using regionprops() and asking for PixelList
props = regionprops(binaryImage, 'PixelList');
  10 件のコメント
Image Analyst
Image Analyst 2021 年 7 月 14 日
Did you read my last comment? No more help will come unless you attach the binary image.
kanika bhalla
kanika bhalla 2021 年 7 月 14 日
I am very sorry Sir @Image Analyst for not attaching image earlier.
I have attached image here for your reference.
Thank you for your time and help!!

サインインしてコメントする。


KSSV
KSSV 2021 年 7 月 1 日
I0 = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/670538/image.png') ;
I1 = rgb2gray(I0) ;
I2 = imbinarize(I1) ;
[y1,x1] = find(I2==0) ; % get black pixels to reduce white background
I = I0(min(y1):max(y1),min(x1):max(x1),:) ; % Get the only black part of the image
I1 = rgb2gray(I) ;
I2 = imbinarize(I1) ;
[y,x] = find(I2) ; % get white pixels in image I
x = x+min(x1) ; y = y+min(y1) ; % white pxiels in original image
imshow(I0)
hold on
plot(x,y,'.r')
  5 件のコメント
kanika bhalla
kanika bhalla 2021 年 7 月 9 日
Thank you Sir @Walter Roberson for your time and reply.
Andrea
Andrea 2023 年 3 月 22 日
@KSSV could you please explain me the
I = I0(min(y1):max(y1),min(x1):max(x1),:) ;
and the
x = x+min(x1) ; y = y+min(y1) ;
lines? Sorry but I have just started to use Matlab and I am still learning:)
Thank you very much!

サインインしてコメントする。

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by