필터 지우기
필터 지우기

Extracting cartesian coordinates from a binarized image of a curved line

조회 수: 1 (최근 30일)
Michiel Firlefyn
Michiel Firlefyn 2018년 4월 23일
댓글: Michiel Firlefyn 2018년 5월 1일
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.
  댓글 수: 1
Michiel Firlefyn
Michiel Firlefyn 2018년 5월 1일
Thanks for answering Sigurd!I managed to extract the coordinates how I wanted by using the bwboundaries command.

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by