[BangPypers] Questions regarding Image cropping

Senthil Kumaran orsenthil at gmail.com
Sun Mar 1 15:51:01 CET 2009


On Sun, Mar 1, 2009 at 1:25 PM, Arunabha Adhikari
<arunabha.adhikari at gmail.com> wrote:
> 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.

You cannot do via PIL to close the Image.show() window.
What you can do is use TkInter to display the Image and you will have
complete control over the Tkinter window.

I found the following snippet that might be useful to you:
http://code.activestate.com/recipes/521918/

Make sure to add root.destroy() when you want to close the Window.

Apart from using Tkinter, the other options available to you is:
- On windows use Win32 api to get hold of window controls.
- Similar for Linux,  there should be window manager specific python
extensions ( gnome + python + eog close function), but I am not sure
about it.

Also, are you willing to play around with subprocess module? There
could be a way  to call it such that it opens in the background and
then you can close it. ( I got to try it too)

# Following two uses the OS's function, but does not do in the background.
>>> os.system('image1.jpg')
0
>>> import subprocess
>>> cout, cin = subprocess.Popen('image1.jpg',shell=True,stdin=subprocess.PIPE,stdout=s
ubprocess.PIPE,stderr=subprocess.PIPE).communicate()
>>>


-- 
Senthil


More information about the BangPypers mailing list