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!
0 件のコメント
回答 (1 件)
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 Center および File Exchange で Image Segmentation and Analysis についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!