[BangPypers] Questions regarding Image cropping
Anand Balachandran Pillai
abpillai at gmail.com
Mon Mar 2 10:21:24 CET 2009
On Sun, Mar 1, 2009 at 1:25 PM, Arunabha Adhikari
<arunabha.adhikari at gmail.com> wrote:
> Dear friends,
> I am a beginner in Python programming. I am not a computer professional I am
> a physicist. I was trying to write a code in python for my own research
> which involves a little image processing. All I need to do is to display an
> image and then select a region of interest using my mouse and finally crop
> out the selected region. I can do this in Matlab using the ginput()
> function. I tried using PIL. But I find that after I issue the command
> Image.show(), the image is displayed but then the program halts there unless
> I exit from the image window. Is there any way to implement what I was
> planning. Do I need to download any other module? Please advise.
The task of selecting an area on an image for processing
is called "rubber-banding". The technique is to XOR the pixels
of the selected region (rectangle). Then get the boundaries
of the region.
I actually wrote a complete image viewer cum editor using wxPython/PIL
many years back. I later on published the rubberbanding part as an ASPN
recipe. If you want to use wxPython, the recipe would be useful.
Btw, this was for an older release of wxPython, so not sure whether
this will work now. However the algorithm is generic and can be mapped
to any GUI library.
The image viewer source code is here. Btw, this is really *ancient*
and an abandoned project - I updated it last in 2003 I guess. However
I guess many of the code there is still generically useful, especially
the convolution filters.
If you are feeling either brave or desperate or both, click on
the following link.
More information about the BangPypers