Extracting cartesian coordinates from a binarized image of a curved line

3 vues (au cours des 30 derniers jours)
Michiel Firlefyn
Michiel Firlefyn le 23 Avr 2018
Hi everyone
After image pre-processing, I obtained the following binarized image:
This is in a 2848x4272 array form and I would like to convert the line to a 2 column matrix with x and y coordinates. Does anyone have any idea how to achieve this?
The code I used to achieve the line is:
img = imread('G1.JPG');
background = imopen(img,strel('disk',60));
surf(double(background(1:8:end,1:8:end))),zlim([0 255]);
set(gca,'ydir','reverse');
I2 = img - background;
grayImage = I2(:, :, 1);
I3 = imadjust(grayImage);
bw = imbinarize(I3);
bw = bwareaopen(bw, 5000);
cc = bwconncomp(bw, 8);
line = false(size(bw));
line(cc.PixelIdxList{1}) = true;
imshow(line);
Thanks!

Réponses (1)

Sigurd Askeland
Sigurd Askeland le 27 Avr 2018
I don't have the Image Processing Toolbox, so I can't recreate your scenario exactly. However, if you have a 2D array of booleans ( true / false, or 1 / 0), this can be translated to an (Nx2) array of the x and y indices of the true pixels.
[m,n] = size(my_image); %my_image to be replaced by your image...
x = ones(m*n,1) * [1:m*n];
y = [1:m*n]' * ones(1,m*n);
coordinates = [x,y]; %All coordinates.
coordinates = coordinates(my_image(:),:); %'true' coordinates.
Note that the x and y values are the number of pixels from the top left corner. A simple transformation can make them into more traditional x- and y-coordinates.
  1 commentaire
Michiel Firlefyn
Michiel Firlefyn le 1 Mai 2018
Thanks for answering Sigurd!I managed to extract the coordinates how I wanted by using the bwboundaries command.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by