# Help in evidencing a region (circular) of a .tiff image and cropping all the rest of the image

I'm asking for the community help since I have problems in cropping an image. I'm having LEED images which are 576*720p, which are made by a big black region at which middle I have the image I'm analizing. Since the region is circular, i would like to single that out of the black region, but I haven't really found a way to do so. By now, if this is the image:

I'm able, via the function "EdgeDetect", to put in evidence the circular region i would like to preserve of the full image:

The circular region is evident, even if it's a little smaller that what's in reality(that's because i thing mathematica takes the edges of variation, which by many means may be closer to the center of the image that in reality). Anyway, I haven't been able to find a function in mathematica (nor to write it, actually I don't how to implement) to get that circular region (and possibly some more) and have the rest of the image cropped out. That would really light my code, and I'm asking if anyone has any idea on how to solve it.

• Just curious... diffraction pattern in a reflecting telescope? (I used ImageAdjust to brighten the image...) – 2012rcampion Apr 15 '15 at 2:29
• you send electrons by that central thing (an electronic gun). Those electrons are then scattered by the sample, and thanks to the periodicity of the surface you will get diffraction spots (in directions normal to the surface), only by electrons that are elastically scattered. The principle is the one of the van laue scattering. There's a nice wikipedia page about LEED: link. What you then have is a less than 2Pi solid angle fluorescent screen to get the image. – Andrea Apr 15 '15 at 17:16
• Try this: Colorize[ImageData[img, Automatic]]. You can see that there is only a one-value difference between the inside and outside of the circle, and that the edges are not sharp enough to reliably detect. If your camera is always mounted in the same place you can use David's cropping method, but otherwise you'll have to align the images manually. – 2012rcampion Apr 15 '15 at 17:40
• unfortunately the sample is not always in the same position since it's moved... that's the main problem. – Andrea Apr 15 '15 at 17:54

img = Import["http://i.stack.imgur.com/JU26d.png"]


As I mentioned in my comment, the image is too dark to detect the central circle. There is only a one-bit difference between the inside and the outside, and amount of noise is too large.

Colorize[ImageData[img, Automatic]]


(In the future I'd suggest marking three points on the rim with colored LEDs, or taking a lights-on and light-off pair to make detection easier.)

We can, however, detect the diffraction spots fairly easily:

LocalAdaptiveBinarize[img, 32, {1, 0, 0.02}]


And from there we can compute the bounding circle:

circle = ComponentMeasurements[ImageData@LocalAdaptiveBinarize[img, 32, {1, 0, 0.02}],


And show it against the original image:

Show[ImageAdjust@img, Graphics[{Red, Circle @@ circle}]]


And finally we can extract the ROI like so:

ImageTrim[img, Through[{Plus, Subtract} @@ circle]]


You will probably have to tweak the values to get all your images to be reliably detected, but all these operations should be pretty fast (as long as you keep the second element of the list argument to LocalAdaptiveBinarize, the standard deviation weight, at zero.)

• That's it! thanks a lot for your help. Apart from the tweaking, it works well – Andrea Apr 15 '15 at 22:17

Click and drop your figure or name it myFig. Then

ImageTake[myFig, {120, 500}, {130, 530}]


• Yes, but how can i get it iterative? Furthermore I'd like the cropping to have always the same dimensions of the image to compare nicely intensity plots made by considering rows of pixels from different images. So that cropping doesn't affect "position" in pixels of the spots. I mean, maybe also finding the center of the profile of the central big spot (the gun) and taking a region starting from there (e.g. always a 200x200 square of pixels) would work. The problem is, I'm not into the feature detection thing.... Thanks for your help – Andrea Apr 15 '15 at 17:21
• @Andrea I don't quite understand what you mean by "iterative." "Iterative" means that you perform an operation (on an image), then perform it on the processed image, then perform it again on that processed image, etc. Do you instead mean "automatic," so that one simply applies the algorithm to an arbitrary source image? – David G. Stork Apr 15 '15 at 17:38
• whops, automatic, every time i plug a similar image it does the same work on it – Andrea Apr 15 '15 at 17:52