Extracting cartesian coordinates from a binarized image of a curved line

3 次查看(过去 30 天)
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!

回答(1 个)

Sigurd Askeland
Sigurd Askeland 2018-4-27
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.

类别

Help CenterFile Exchange 中查找有关 Image Segmentation and Analysis 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by