Extracting cartesian coordinates from a binarized image of a curved line

2 Ansichten (letzte 30 Tage)
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!

Antworten (1)

Sigurd Askeland
Sigurd Askeland am 27 Apr. 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 Kommentar
Michiel Firlefyn
Michiel Firlefyn am 1 Mai 2018
Thanks for answering Sigurd!I managed to extract the coordinates how I wanted by using the bwboundaries command.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by