On Monday, June 14, 2010 10:32:48 pm Daniel Jones wrote:
> Hi matplotlib users,
> 
> I'm trying to write a script to loop through a bunch of tiff files,
> display each image, and choose to accept or reject each image.
> Something like:
> 
> for f in files:
>    im = imread(f)
>    imshow(im)
>    # Accept keyboard input to accept or reject image
>    # Close the image
> 
> 
> The problem is that I can't figure out how to show multiple images in
> series. I can't use matplotlib.pyplot.show() because that can only be
> used once at the very end of a script, and I don't want to show all
> the images at once. matplotlib.pyplot.draw() seemed like a promising
> candidate, but it only seems to work if I've already used show() once
> in the script. It seems like there should be a simple way to do this,
> but I can't quite seem to find it.
> 
> Thanks,
> Daniel

Hi Daniel,

in the attached script I propose two solutions for your problem (just 
uncomment first region and comment second to test the first proposal). The 
first 
uses plt.waitforbuttonpress and the second key-press-events.

Kind regards,
Matthias
import numpy as np
import matplotlib.pyplot as plt

file_list = ['a', 'b', 'c', 'd']

ax = plt.subplot(111)

### vvv --- first attempt using 'plt.waitforbuttonpress' -----------------------
##plt.hold(False)
##for index, file in enumerate(file_list):
##    # im = plt.imread(file)
##    im = np.random.uniform(size=(30, 20)) # some random data
##    ax.imshow(im)
##    ax.set_title("use (key-press) or reject (button press) image %i" % (index))
##    plt.draw()
##    result = plt.waitforbuttonpress()
##    print "result :", result

##plt.show()
### ^^^ --- first attempt using 'plt.waitforbuttonpress' -----------------------


# vvv --- second attempt using 'plt.connect and key press events' ------------

def event_fct(event):
    """ evaluate key-press events """
    global counter
    if event is None:
        counter = 0
    else:
        if event.key in ['r', 'u']:
            if event.key in 'r':
                print "reject image"
            elif event.key in 'u':
                print "use image"

            # go to next image
            counter += 1
        else:
            print "Key >%s< is not defined" % (event.key)
            return

    # im = plt.imread(file_list[counter])
    im = np.random.uniform(size=(30, 20)) # some random data
    ax.imshow(im)
    ax.set_title("[u]se or [r]eject image %i by key press" % (counter))
    plt.draw()

event_fct(None) # initial setup
plt.connect('key_press_event', event_fct)
plt.show()
# ^^^ --- second attempt using 'plt.connect and key press events' ------------
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to