From: Tomas Musil Date: Tue, 20 Mar 2012 23:08:49 +0000 (+0100) Subject: Greyscale, im_debug X-Git-Url: http://git.tomasm.cz/imago.git/commitdiff_plain/1b3674eafe2ed9104327b2af609e9c0cba69661a?ds=sidebyside Greyscale, im_debug greyscale.py: Short script to test different methods of transforming RGB images to greyscale. im_debug.py: Simple script using pygame to display images for debugging purposes. image.jpg: Photo of a goban with game (guess which one) being replayed. Something to test these scripts on. --- 1b3674eafe2ed9104327b2af609e9c0cba69661a diff --git a/greyscale_test.py b/greyscale_test.py new file mode 100644 index 0000000..97ed3ac --- /dev/null +++ b/greyscale_test.py @@ -0,0 +1,20 @@ +import Image, ImageMath +import im_debug +import sys + +im = Image.open('./image.jpg') +im_debug.show(im, 'Original image') + +im_l = im.convert('L') +im_debug.show(im_l, 'ITU-R 601-2 luma transform') + +im_rgb = im.convert('L', (float(1)/3, float(1)/3, float(1)/3, 0)) +im_debug.show(im_rgb, '(R+G+B)/3 transform') + +s1, s2 = im.size +im2 = Image.new('L', (s1 * 2, s2)) +im2.paste(im_l, (0, 0, s1, s2)) +im2.paste(im_rgb, (s1, 0, 2*s1, s2)) +im_debug.show(im2, 'Both transforms side by side') + +im_debug.show(ImageMath.eval("convert(abs(a - b)*5, 'L')", a=im_l, b=im_rgb), 'Difference') diff --git a/im_debug.py b/im_debug.py new file mode 100644 index 0000000..9b72ed3 --- /dev/null +++ b/im_debug.py @@ -0,0 +1,23 @@ +import pygame +import Image + +def show(image, caption=''): + if image.mode != 'RGB': + image = image.convert('RGB') + pygame.init() + if caption: + caption = "Imago: " + caption + else: + caption = "Imago" + pygame.display.set_caption(caption) + pygame.display.set_mode(image.size) + main_surface = pygame.display.get_surface() + picture = pygame.image.frombuffer(image.tostring(), image.size, image.mode) + main_surface.blit(picture, (0, 0)) + pygame.display.update() + while True: + events = pygame.event.get() + for event in events: + if event.type == pygame.QUIT or event.type == pygame.KEYDOWN: + pygame.quit() + return diff --git a/image.jpg b/image.jpg new file mode 100644 index 0000000..a66aae9 Binary files /dev/null and b/image.jpg differ