Extract a predefined zone within an imageDear 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
Re: Extract a predefined zone within an imageMaybe. You might be able to create a model using statistics about the pixel values in the image to create the two threshold values the filter needs. You might want to smooth the picture before the canny filter (not inside the canny filter) so you can build the model with the smoothed pixels. (Edit: the internal canny filter blur is better because it keeps track of floating point data. An external blur will reduce the floating point data to integer pixels values 0..255 in the blurred image, and most of your pixels in the dark image are 0..10 or so.)
https://en.wikipedia.org/wiki/Canny_edge_detector describes how the canny filter works; the large threshold value (very small for your pictures) is where a line starts. Two adjacent pixels must be different by that much. The line is "followed" until it drops below the small threshold value (very, very small for your pictures). "The two threshold values are empirically determined and their definition will depend on the content of a given input image."-Wikipedia
Are colors important in these images? If not, you might want to reduce the image to gray scale. It will become a simpler problem, I think. You could make a distribution of the gray scale values...
What will you do with the line after you get it in an image? Is it just a visualization, or will you do more computations on that image? The clustering approach might still work well if you need a center of mass and radius.
Re: Extract a predefined zone within an imageDear Craige,
we deployed the solution in an automated way but we still need to adapt manually the threshold parameters because photos are heterogeneous. do you think it is possible to automate this step?
Thanks a lot,
Samir
Re: Extract a predefined zone within an imageDear Craige,
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,
Samir
Re: Extract a predefined zone within an imageTake 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></GETPIXELS>
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.
Re: Extract a predefined zone within an imageDear 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.
Krs,
Samir
Re: Extract a predefined zone within an imageYes. Get a matrix of the pixel values for the entire image, something like
image<
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.