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. curves.png

10 comentarios

KSSV
KSSV el 15 de Mayo de 2019
I think they are alredy wll sorted......what you are expecting?
JRose
JRose el 15 de Mayo de 2019
Editada: JRose el 15 de Mayo de 2019
ther are not sorted continuously. normally it will be sorted in the way the image is read by matlab. i need it to be sorted along the curves as it is drawn.
Jan
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
JRose el 15 de Mayo de 2019
Editada: JRose el 15 de Mayo de 2019
Yes.. iteratively i wish to sort the points from the left end th the right end of this curve. the x and y coordinates are given in the array.txt. Your help will be appreciated. Thank you.
Jan
Jan el 15 de Mayo de 2019
Editada: Jan el 15 de Mayo de 2019
Now please explain, if this is the only case, or if you have a set of diffente input data, which might be less clear. "Left end" need not necessarily unique. Do you want to select it manually with the mouse or automatically?
JRose
JRose el 16 de Mayo de 2019
@Jan No sir. This is not the only case. I just need a general program to collect all the connecting white points in any image in a continuous manner in any direction just like tracing the structure. Not with the use of mouse. Just to sort the pixel coordinates from the binary image. For closed structures it's easy. But for curves and lines with different angle, I couldn't find a solution.
Jan
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
JRose el 17 de Mayo de 2019
if we plot the lines it matches excatly. what i need is to get the points in an ordered manner. if the coordinate of white pixel on th eleft most end is 1st element of the array, the i need the send element as the nearest white pixel and so on. i have pllotted the points after saving it to array from the image and got excatly what you sai. but i couldn't get it as i mentioned above. my purpose is to take a line profile along these edges of the coordinate. thats why i need it in an ordered manner. please correct me if i'm wrong
Jan
Jan el 17 de Mayo de 2019
Editada: Jan 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).
JRose
JRose el 24 de Mayo de 2019
@Jan: The input image is provided which is binarized and skelotonized. after that i saved the points in an array. This array is provided in the text file. You said tht it is already sorted. My question is: if i trace through the line from one end to the other, i will get certain cordinates. whether i can save these coordinates in an array as i trace through the line. when i go through the points in the array, its not ordered from one end of the skeletonized image to the other end.

Iniciar sesión para comentar.

Respuestas (2)

KSSV
KSSV el 16 de Mayo de 2019

0 votos

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.
untitled.bmp

5 comentarios

JRose
JRose el 17 de Mayo de 2019
if we plot the lines it matches excatly. what i need is to get the points in an ordered manner. if the coordinate of white pixel on th eleft most end is 1st element of the array, the i need the send element as the nearest white pixel and so on. i have pllotted the points after saving it to array from the image and got excatly what you sai. but i couldn't get it as i mentioned above. my purpose is to take a line profile along these edges of the coordinate. thats why i need it in an ordered manner. please correct me if i'm wrong
KSSV
KSSV el 17 de Mayo de 2019
The points are in zig-zag way..you want a smooth curve instead?
JRose
JRose el 17 de Mayo de 2019
no sir. I just need the points as it is in the figure. i have collected the points after skeletonizing. so it will be pixel by pixel. i just need to get the coordinates in an orderly fashion.
KSSV
KSSV el 17 de Mayo de 2019
They are already in orderly fashion.
comet(x,y)
JRose
JRose el 24 de Mayo de 2019
Thank you for you answers.

Iniciar sesión para comentar.

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 16 de Mayo de 2019

0 votos

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.

Etiquetas

Preguntada:

el 15 de Mayo de 2019

Comentada:

el 24 de Mayo de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by