Sorting points of image
Mostrar comentarios más antiguos
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 comentarios
KSSV
el 15 de Mayo de 2019
I think they are alredy wll sorted......what you are expecting?
Jan
el 15 de Mayo de 2019
So you want to find a start point at one of the ends and determine the nearest neighbor iteratively?
JRose
el 16 de Mayo de 2019
Jan
el 16 de Mayo de 2019
@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
el 17 de Mayo de 2019
@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
el 24 de Mayo de 2019
Respuestas (2)
KSSV
el 16 de Mayo de 2019
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
el 16 de Mayo de 2019
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.
Categorías
Más información sobre Image Arithmetic en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!