Sorting points of image
이전 댓글 표시
I have an image with white curves on black background. How to Sort the white pixels in an array? the pixel array is attached.Thanks in advance. 

댓글 수: 10
KSSV
2019년 5월 15일
I think they are alredy wll sorted......what you are expecting?
Jan
2019년 5월 15일
So you want to find a start point at one of the ends and determine the nearest neighbor iteratively?
JRose
2019년 5월 16일
Jan
2019년 5월 16일
@JRose: The question is still not clear. Now you mention "sort the pixel coordinates from the binary image", but formerly it lookewd like you do have the corrdinates already. In the posted screenshot you do not have single points, but an area with several points beside eachother, about 8 or 10.
Please explain uniquely, what your inputs are and what you want to achieve.
JRose
2019년 5월 17일
@JRose: I do not understand, what "if we plot the lines it matches excatly" means. "a line profile along these edges of the coordinate" is not clear to me also.
You do not answer my question, what exactly your inputs are. A screenshot in the memory, a saved image, a text file of coordinates? You have posted the file array.txt and show an image, but which of them is the data you want to process? You mention "the white pixels in an array", but arrays do not have pixels, and in the image, the drawn line has a certain width of about 8 pixels and it is not clear, which of these many pixels you consider as "start" and how you want to treat this area (which is not a 2D line).
Please read How to ask a good question
JRose
2019년 5월 24일
답변 (2개)
KSSV
2019년 5월 16일
I = imread('curves.png');
I1 = rgb2gray(I);
[y,x] = find(I1) ;
imshow(I)
hold on
plot(x,y,'r')
You see the lines are in order...that's why I am able to join them by a line, which lie exactly on the white region.

Sulaymon Eshkabilov
2019년 5월 16일
Hi,
What you are trying to find out where the white pixels are residing, right?!
% This locates all white pixels accurately
AA = imread('curves.png');
A1 = AA(:,:,1);
A2 = AA(:,:,2);
A3 = AA(:,:,3);
Index1 = find(A1>0);
Index2 = find(A2>0);
Index3 = find(A3>0);
B1 = A1(Index1);
B2 = A2(Index2);
B3 = A3(Index3);
DATA = [B1, B2, B3];
imshow(DATA), shg
%% Given coordinates: don't seem to correct at all
array = load('array.txt');
AA = imread('curves.png');
A1 = AA(:,:,1);
A2 = AA(:,:,2);
A3 = AA(:,:,3);
B1 = A1(array(:,:));
B2 = A2(array(:,:));
B3 = A3(array(:,:));
DATA = [B1, B2, B3];
imshow(DATA), shg
Good luck.
카테고리
도움말 센터 및 File Exchange에서 Image Arithmetic에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!