khushbu
khushbu

Reputation: 47

Extract pixel coordinates in scilab

I have extracted edge using image processing then I selected pixel coordinate using xclick of extracted edge.Is this correct or there is need of reverse y axis coordinate?(Extracted edge is white on black background) I want to automatically extracted pixel coordinates of extracted edge not by mouse selection.Is there is any command available in scilab?(I use canny edge detector and morphological filter to extract edge)

Please give me some suggestions

Thanks

Upvotes: 1

Views: 1556

Answers (1)

Attila
Attila

Reputation: 615

1.) Whether to reverse the y coordinte or not, depends on the further processing. Any coordinate system can be used if you need only relative measurements and the true orientation of your features is not important (e.g. reversing top and bottom makes no difference if you simply want to count objects or droplets). Hovewer if you want to indicate your found features by plotting a dot, or a line, or a rectangle (e.g. with plot2d or xrect) or a number (e.g. with xnumb) over the image, then it's necessary to match the two coordinate sytems. I recommend this second option and to plot your result over the original image, since this is the easiest way to check your results. 2.) Automatic coordinate extraction can be made by the find function: it returns those indices of the matrix, where the expression is true.

IM=[0,0,0,1;0,0,0,1;0,1,1,1;1,1,0,0];   //edge image, edge = 1, background = 0
disp(IM,"Edge image");
[row,col]=find(IM==1);    //row & column indices where IM = 1 (= edge)
disp([row',col'],"Egde coordinates (row, col)");

If your "Egde image" marks the edges not with 1 (or 255, pure white pixel) but with a relatively high number (bright pixel), then you can modify the logical expression of the find function to detect pixels with a value above a certain threshold:

[row,col]=find(IM>0.8);    //if edges > a certain threshold, e.g. 0.8

EDIT: For your specific image: enter image description here Try the following code:

imagefile="d:\Attila\PROJECTS\Scilab\Stackoverflow\MORPHOLOGICAL_FILTERING.jpg";
//you have to modify this path!
I=imread(imagefile); 
IM=imcrop(I,[170,100,950,370]);   //discard the thick white border of the image
scf(0); clf(0);
ShowImage(IM,'cropped image');
threshold=100;    //try different values between 0-255 (black - white)
[row,col]=find(IM>threshold);
imheight=size(IM,"r");   //image height
row=imheight-row+1;   //reverse y axes coordinates (0 is at top)
plot2d(col,row,style=0);  //plot over the image (zoom to see the dots)
scf(1); clf(1);  //plot separate graph
plot2d(col,row,style=0);

If you play with the threshold parameter, you will see how the darker or whiter pixels are found.

Upvotes: 1

Related Questions