Dear Everybody,
I want to tow know if it is possible to extract with a script the pixels within the predefined circle of my image (see attached).
Thanks in advance for your help.
Krs,
Samir
Take a look at the canny filter example in the scripting index. The parameters are on sliders and may be too touchy if your data varies in intensity, but for the example image I used
Slider Settings in Scripting Index example
To get this
Canny filter detects edges
The noise in the image was smoothed, a lot, by the top two sliders. The bottom two sliders were adjusted to values appropriate for these pixel intensities. The script is in the example; you might be able to automate your process if the pictures are similar enough. The output is a B&W or ones and zeros image. You could grab those pixels in a matrix for further processing.
You might also want to do some analysis of the pixel colors. Maybe clustering would give you a dark blue and darker blue pair of clusters. Maybe you could use the x-y coordinates of the dark blue clustered pixels. for example:
// load the test image img = open("$desktop/large.png","png"); // grab the rgb data from the image {r,g,b} = img<<getpixels("rgb"); // make a data table from the r,g,b matrices dt = newtable("imgdata", newcolumn("r",numeric,setvalues(r)), newcolumn("g",numeric,setvalues(g)), newcolumn("b",numeric,setvalues(b)) ); // cluster the table. I got this script by saving it from // an interactive run of the clustering platform p = dt<<K Means Cluster( Y( :r, :g, :b ), {Number of Clusters( 3 ), Name( "K-Means Clustering" ), Go}, SendToReport( Dispatch( {}, "Control Panel", OutlineBox, {Close( 1 )} ) ) ); // add a column beside the rgb cols p<<saveClusters; // turn the column of clusters into a 2D mat mat = shape(dt:cluster<<getvalues,nrows(r),ncols(r)); // there are three clusters in "mat", fiddle with rgb... newwindow("cluster",newimage("rgb",{mat==1,mat==2,mat==3}));
Clustering results turned into an image
It might make more sense to work with the XY coordinates of the clustered pixels to find the parameters you want.
Yes. Get a matrix of the pixel values for the entire image, something like
image<<getpixels (check the scripting index, I'm away from my desk right now).
You can get the pixels as separate r,g,b channels or as a combined JMP color.
Next, you'll need a mask matrix of the same dimensions, with ones for the pixels to keep and zeros for the pixels to reject. You can use a paint program with white for one and black for zero. Load that image and get just one channel, red perhaps (r,g,b should all be the same for the black and white image), which will have the zero and one values.
Now decide what you want the result to be: just an unordered list of only the interesting pixels? Or a matrix the same size as before with the uninteresting values set to zero?
imageMatrix[ Loc(mask) ] will give you the unordered pixels where mask had non-zero values.
imageMatrix mask will give you zero where the mask is zero, original values where the mask is one. ( is the element-wise multiply. * is matrix-algebra multiply...not what you want.)
This post might help.
Dear Craige,
Thank you for the suggestion.
Unfortunately, the localisation of the circle inside the image may move from on photo to another (not standardized yet).
My question is if it possible de detect the contours of the circle in an automatics way.
The canny filter is really helpful.
I will try to automate the process.
The clustering is also very interesting but the result is less clear for some other photos.
Thanks a lot for your help,