Exemple #1
0
	def process(self, image):
		yield 'Start...', image
		simage = ImageOps.autocontrast(image, 20)
		s_width, s_height = image.size[0] / 2, image.size[1] / 2
		simage = image.resize((s_width, s_height))
		simage = colors.convert_to_luminosity(simage)
		simage = simage.filter(ImageFilter.SMOOTH)
		yield 'Mask...', simage
		mask = ImageEnhance.Brightness(simage).enhance(2)
		mask = ImageOps.posterize(mask, 2)
		mask = ImageOps.autocontrast(mask, 20)
		yield 'Curves...', mask
		simage = ImageEnhance.Contrast(simage).enhance(2)
		yield 'posterize...', simage
		simage = ImageOps.posterize(simage, 2)
		yield 'Red...', simage
		red_img = self._apply_color(simage, (255, 0, 0), mask)
		yield 'green...', red_img
		green_img = self._apply_color(simage, (0, 255, 0), mask)
		yield 'blue...', green_img
		blue_img = self._apply_color(simage, (0, 0, 255), mask)
		yield 'yellow...', blue_img
		yellow_img = self._apply_color(simage, (255, 255, 0), mask)
		yield 'Merge...', yellow_img
		image = image.copy()
		image.paste(red_img, (0, 0, s_width, s_height))
		image.paste(green_img, (s_width, 0, s_width * 2, s_height))
		image.paste(yellow_img, (0, s_height, s_width, s_height * 2))
		image.paste(blue_img, (s_width, s_height, s_width * 2, s_height * 2))
		yield 'Done', image
Exemple #2
0
	def process(self, image):
		yield 'Start...', image
		simage = ImageOps.autocontrast(image, 20)
		s_width, s_height = image.size[0] / 2, image.size[1] / 2
		simage = image.resize((s_width, s_height))
		simage = simage.filter(ImageFilter.SMOOTH)
		yield 'Mask...', simage
		mask = ImageEnhance.Brightness(simage).enhance(2)
		mask = ImageOps.posterize(mask, 2)
		mask = ImageOps.autocontrast(mask, 20)
		yield 'posterize...', mask
		simage = ImageEnhance.Brightness(simage).enhance(2)
		simage = ImageOps.equalize(simage)
		simage = simage.filter(ImageFilter.SMOOTH_MORE)
		simage = ImageOps.posterize(simage, 1)
		yield 'Red...', simage
		red_img = self._apply_color(simage, 0.25, mask)
		yield 'green...', red_img
		green_img = self._apply_color(simage, 0.75, mask)
		yield 'blue...', green_img
		blue_img = self._apply_color(simage, 1, mask)
		yield 'yellow...', blue_img
		yellow_img = self._apply_color(simage, 0.5, mask)
		yield 'Merge...', yellow_img
		image = image.copy()
		image.paste(red_img, (0, 0, s_width, s_height))
		image.paste(green_img, (s_width, 0, s_width * 2, s_height))
		image.paste(yellow_img, (0, s_height, s_width, s_height * 2))
		image.paste(blue_img, (s_width, s_height, s_width * 2, s_height * 2))
		yield 'Done', image
Exemple #3
0
	def process(self, image):
		yield 'Start...', image
		s_width, s_height = image.size[0] / 2, image.size[1] / 2
		simage = image.resize((s_width, s_height))
		yield 'posterize...', simage
		simage = simage.convert("L")
		yield 'posterize 2...', simage
		simage = ImageEnhance.Brightness(simage).enhance(2)
		simage = ImageOps.equalize(simage)
		yield 'posterize 3...', simage
		simage = ImageOps.autocontrast(simage, 20)
		yield 'posterize 4...', simage
		simage = ImageOps.posterize(simage, 1)
		colors = []
		colors.extend([255] * 128)
		colors.extend([0] * 128)
		colors.extend([0] * 128)
		colors.extend([255] * 128)
		colors.extend([0] * 256)
		simage = simage.convert("RGB").point(colors)
		yield 'Red...', simage
		red_img = self._apply_color(simage, 0.82)
		yield 'green...', red_img
		green_img = self._apply_color(simage, 0.75)
		yield 'blue...', green_img
		blue_img = self._apply_color(simage, 0)
		yield 'yellow...', blue_img
		yellow_img = self._apply_color(simage, 0.6)
		yield 'Merge...', yellow_img
		image = image.copy()
		image.paste(red_img, (0, 0, s_width, s_height))
		image.paste(green_img, (s_width, 0, s_width * 2, s_height))
		image.paste(yellow_img, (0, s_height, s_width, s_height * 2))
		image.paste(blue_img, (s_width, s_height, s_width * 2, s_height * 2))
		yield 'Done', image
Exemple #4
0
	def process(self, image):
		yield 'Start...', image
		s_width, s_height = image.size[0] / 3, image.size[1] / 3
		simage = image.resize((s_width, s_height))
		yield 'posterize...', simage
		simage = simage.convert("L")
		simage = ImageEnhance.Brightness(simage).enhance(2)
		simage = ImageOps.equalize(simage)
		simage = ImageOps.autocontrast(simage, 20)
		simage = ImageOps.posterize(simage, 1)
		yield 'colors...', simage
		colormap = []
		colormap.extend([255] * 128)
		colormap.extend([0] * 128)
		colormap.extend([0] * 128)
		colormap.extend([255] * 128)
		colormap.extend([0] * 256)
		simage = simage.convert("RGB").point(colormap)
		image = image.copy()
		for x in xrange(3):
			for y in xrange(3):
				yield 'Img %d...' % (x * 3 + y + 1), simage
				simg = colors.apply_hue_lightness_saturation(simage,
						((x * 3 + (2.9 - y)) / 10.), 0, 1, True)
				image.paste(simg, (x * s_width, y * s_height,
						(x + 1) * s_width, (y + 1) * s_height))
		yield 'Done', image
Exemple #5
0
def posterize(image, bits, amount=100):
    """Apply a filter
    - amount: 0-1"""
    image = imtools.convert_safe_mode(image)
    posterized = imtools.remove_alpha(image)
    posterized = ImageOps.posterize(posterized, bits)
    if imtools.has_alpha(image):
        imtools.put_alpha(posterized, imtools.get_alpha(image))
    if amount < 100:
        return imtools.blend(image, posterized, amount / 100.0)
    return posterized
Exemple #6
0
def posterize(image, bits, amount=100):
    """Apply a filter
    - amount: 0-1"""
    image = imtools.convert_safe_mode(image)
    posterized = imtools.remove_alpha(image)
    posterized = ImageOps.posterize(posterized, bits)
    if imtools.has_alpha(image):
        imtools.put_alpha(posterized, imtools.get_alpha(image))
    if amount < 100:
        return imtools.blend(image, posterized, amount / 100.0)
    return posterized
Exemple #7
0
def get_hash(_im, size=__CONST_SIZE, posterize=False):
    im = Image.open(_im).resize(size).convert('L')
    if posterize:
        im = ImageOps.posterize(im, __CONST_POSTERIZE_BIT)

    pixels = im.load()
    avg = sum([pixels[coord] for coord in __CONST_COORDINATES]) / __CONST_PIXEL_COUNT_FLOAT
    _hash = reduce(__CONST_HASH_REDUCE_FUNC(avg, pixels),
                   __CONST_PIXEL_COUNT_LIST,
                   0) >> 1    # after 64 left-shifts, the result is 65bit, need shift right once to get a 64bit hash

    return _hash
def processImage(indir, filename, cam, master_image=None):
    infilepathfilename = inpath(indir, filename)
    thumbpathfilename = thumbpath(indir, filename)
    mediumpathfilename = mediumpath(indir, filename)
    print "Processing %s\n" % (infilepathfilename)

    thumbexists = os.path.exists(thumbpathfilename)
    mediumexists = os.path.exists(mediumpathfilename)

    cropped_img = None

    if not (thumbexists and mediumexists):

        try :
            img = Image.open(infilepathfilename)
        except IOError:
            print "Cannot open file %s" % infilepathfilename

        cropped_img = crop_image(img, cam.croparea)

        if (not mediumexists) and (not cropped_img==None) :
            cropped_img.thumbnail(mediumsize, Image.ANTIALIAS)
            try :
                cropped_img.save(mediumpathfilename, "JPEG")
            except IOError:
                print "Cannot save mediumres image %s" % mediumpathfilename

        if (not thumbexists) and (not cropped_img==None):
            try:
                cropped_img.thumbnail(thumbsize, Image.ANTIALIAS)
            except IOError:
                print "Cannot make thumbnail %s" % thumbpathfilename

            if master_image != None:
                #compare current image with Master and make a box around the change
                diff_image = ImageOps.posterize(ImageOps.grayscale(ImageChops.difference(master_image, cropped_img)),1)
                rect = diff_image.getbbox()
                if rect != None:
                    ImageDraw.Draw(cropped_img).rectangle(rect, outline="yellow", fill=None)
            try :
                cropped_img.save(thumbpathfilename, "JPEG")
            except IOError:
                print "Cannot save thumbnail %s" % thumbpathfilename

  
    # done processing, move raw file to storage, so we won't process it again.
    infilepathfilename = inpath(indir, filename)
    hirespathfilename = hirespath(indir, filename)
    
    shutil.move(infilepathfilename,hirespathfilename)

    # return the thumbnail image
    return cropped_img
Exemple #9
0
    def render(self,im):
        im2 = im.copy()
        if self.grayscale:
            im2 = ImageOps.grayscale(im2)        
            im2 = ImageOps.colorize(im2,"black","white")    
        if self.posterized:
            im2 = ImageOps.autocontrast(im2)                
            im2 = ImageOps.posterize(im2,self.posterize_bits)
            im2 = ImageOps.autocontrast(im2)
        if self.gridlines > 0:
            im2 = draw_grid(im2,self.gridlines)

        data = im2.tostring()
        surface = pygame.image.fromstring(data, im2.size, im2.mode)
        screen.blit(surface,(0,0))
        pygame.display.flip()
Exemple #10
0
def __get_hash(im_path, size=(8, 8), posterize=False):
    im = Image.open(im_path).resize(size).convert('L')
    if posterize:
        im = ImageOps.posterize(im, 6)    # 64 = 2 ** 6

    pixels = im.load()

    avg = 0
    for i in range(size[0]):
        for j in range(size[1]):
            avg += pixels[i, j]
    avg /= 64.

    _hash = 0
    for i in range(size[0] * size[1]):
        _hash += 0 if pixels[i % 8, i / 8] < avg else 1
        _hash <<= 1

    return hex(_hash >> 1)
Exemple #11
0
from __future__ import division

import Image
import ImageOps

source_files = [
    '../../data/vort_sim/single_vort_sim_0001.tif',
    '../../data/vort_sim/single_vort_sim_0002.tif'
]

for source_file in source_files:
    dest_file = source_file.replace('.tif', '.txt')
    with open(dest_file, 'w') as f:
        original = Image.open(source_file)
        bit_8 = original.convert("L")
        bit_4 = ImageOps.posterize(bit_8, 4)
        for pix in bit_4.getdata():
            f.write(str(pix) + '\n')
Exemple #12
0
def processImage(indir, filename, cam, master_image=None):
    global images_to_process
    logging.info("Starting processImage()")
    images_to_process = True    # only for testing purposes
    try:
        infilepathfilename = inpath(indir, filename)
        thumbpathfilename = thumbpath(indir, filename)
        mediumpathfilename = mediumpath(indir, filename)
        logging.info("Processing %s" % (infilepathfilename))
    
        thumbexists = os.path.exists(thumbpathfilename)
        mediumexists = os.path.exists(mediumpathfilename)
    
        cropped_img = None
    
        if not (thumbexists and mediumexists):
            img = None
    
            try :
                img = Image.open(infilepathfilename)
            except IOError, e:
                logging.error("Cannot open file %s: %s" % (infilepathfilename, repr(e)))
                
            if img:
                cropped_img = crop_image(img, cam.croparea)
                del img     # close img

            if cropped_img == None:
                logging.error("Failed to crop image %s, croparea: %s" % (infilepathfilename, str(cam.croparea)))
                # crop failure is likely due to attempting to process the
                # incoming image while it is still being uploaded. Return from
                # processImage() here and leave image in incoming dir--don't
                # mark it "done" by moving it to the hires dir. When we get
                # around to processing this image again, it will probably work
                # correctly.  However, if the image mod time is more than an
                # hour old, it's not likely to still be uploading, so assume
                # it's just broken and let the normal code move it to hires
                # so we don't try to process it again
                if os.path.getmtime(infilepathfilename) >= (time.time() - 3600):
                    logging.info("Returning from processImage()" \
                                 + ", leaving original image in place")
                    return cropped_img
    
            if (not mediumexists) and (not cropped_img==None) :
                cropped_img.thumbnail(mediumsize, Image.ANTIALIAS)
                try :
                    cropped_img.save(mediumpathfilename, "JPEG")
                except IOError:
                    logging.error("Cannot save mediumres image %s" % mediumpathfilename)
    
            if (not thumbexists) and (not cropped_img==None):
                try:
                    cropped_img.thumbnail(thumbsize, Image.ANTIALIAS)
                except IOError:
                    logging.error("Cannot make thumbnail %s" % thumbpathfilename)
    
                if master_image != None:
                    #compare current image with Master and make a box around the change
                    diff_image = ImageOps.posterize(ImageOps.grayscale(ImageChops.difference(master_image, cropped_img)),1)
                    rect = diff_image.getbbox()
                    if rect != None:
                        ImageDraw.Draw(cropped_img).rectangle(rect, outline="yellow", fill=None)
                try :
                    cropped_img.save(thumbpathfilename, "JPEG")
                except IOError:
                    logging.error("Cannot save thumbnail %s" % thumbpathfilename)
    
      
        # done processing, move raw file to storage, so we won't process it again.
        infilepathfilename = inpath(indir, filename)
        hirespathfilename = hirespath(indir, filename)
        
        shutil.move(infilepathfilename,hirespathfilename)
Exemple #13
0
from __future__ import division

import Image
import ImageOps

source_files = ['../../data/vort_sim/single_vort_sim_0001.tif', '../../data/vort_sim/single_vort_sim_0002.tif']

for source_file in source_files:
    dest_file = source_file.replace('.tif', '.txt')
    with open(dest_file, 'w') as f:
        original = Image.open(source_file)
        bit_8 = original.convert("L")
        bit_4 = ImageOps.posterize(bit_8, 4)
        for pix in bit_4.getdata():
            f.write(str(pix)+'\n')
Exemple #14
0
def processImage(indir, filename, cam, master_image=None):
    global images_to_process
    logging.info("Starting processImage()")
    images_to_process = True  # only for testing purposes
    try:
        infilepathfilename = inpath(indir, filename)
        thumbpathfilename = thumbpath(indir, filename)
        mediumpathfilename = mediumpath(indir, filename)
        logging.info("Processing %s" % (infilepathfilename))

        thumbexists = os.path.exists(thumbpathfilename)
        mediumexists = os.path.exists(mediumpathfilename)

        cropped_img = None

        if not (thumbexists and mediumexists):
            img = None

            try:
                img = Image.open(infilepathfilename)
            except IOError, e:
                logging.error("Cannot open file %s: %s" %
                              (infilepathfilename, repr(e)))

            if img:
                cropped_img = crop_image(img, cam.croparea)
                del img  # close img

            if cropped_img == None:
                logging.error("Failed to crop image %s, croparea: %s" %
                              (infilepathfilename, str(cam.croparea)))
                # crop failure is likely due to attempting to process the
                # incoming image while it is still being uploaded. Return from
                # processImage() here and leave image in incoming dir--don't
                # mark it "done" by moving it to the hires dir. When we get
                # around to processing this image again, it will probably work
                # correctly.  However, if the image mod time is more than an
                # hour old, it's not likely to still be uploading, so assume
                # it's just broken and let the normal code move it to hires
                # so we don't try to process it again
                if os.path.getmtime(infilepathfilename) >= (time.time() -
                                                            3600):
                    logging.info("Returning from processImage()" \
                                 + ", leaving original image in place")
                    return cropped_img

            if (not mediumexists) and (not cropped_img == None):
                cropped_img.thumbnail(mediumsize, Image.ANTIALIAS)
                try:
                    cropped_img.save(mediumpathfilename, "JPEG")
                except IOError:
                    logging.error("Cannot save mediumres image %s" %
                                  mediumpathfilename)

            if (not thumbexists) and (not cropped_img == None):
                try:
                    cropped_img.thumbnail(thumbsize, Image.ANTIALIAS)
                except IOError:
                    logging.error("Cannot make thumbnail %s" %
                                  thumbpathfilename)

                if master_image != None:
                    #compare current image with Master and make a box around the change
                    diff_image = ImageOps.posterize(
                        ImageOps.grayscale(
                            ImageChops.difference(master_image, cropped_img)),
                        1)
                    rect = diff_image.getbbox()
                    if rect != None:
                        ImageDraw.Draw(cropped_img).rectangle(rect,
                                                              outline="yellow",
                                                              fill=None)
                try:
                    cropped_img.save(thumbpathfilename, "JPEG")
                except IOError:
                    logging.error("Cannot save thumbnail %s" %
                                  thumbpathfilename)

        # done processing, move raw file to storage, so we won't process it again.
        infilepathfilename = inpath(indir, filename)
        hirespathfilename = hirespath(indir, filename)

        shutil.move(infilepathfilename, hirespathfilename)
Exemple #15
0
 ##PIL_IMAGE

import PIL
import Image
import io
import ImageOps
import ImageFilter


image = Image.open("Cartilagini.png")

a=ImageOps.solarize(image, threshold=128) 
a.show()
bits=2
b=ImageOps.posterize(image, bits) 
b.show()


imout1 = image.filter(ImageFilter.EDGE_ENHANCE)
imout1.show()


imout2 = image.filter(ImageFilter.EDGE_ENHANCE_MORE)
imout2.show()


imout3 = image.filter(ImageFilter.EMBOSS)
imout3.show()


imout4 = image.filter(ImageFilter.FIND_EDGES)
Exemple #16
0
import pycisco.cipimage as cipimage
import pycisco.cmxml as cmxml

WIDTH = 132
HEIGHT = 64

if __name__ == '__main__':
    import sys

    fname = sys.argv[1]
    outfname = sys.argv[2]

    im = Image.open(fname)

    #im = im.resize((WIDTH, HEIGHT))

    im_l = im.convert('L')

    im_post = ImageOps.posterize(im_l, 2)

    im_post.show()

    data = dump_cip(im_post)

    width, height = im_l.size

    outf = open(outfname, 'w')
    
    xml = cmxml.PHONE_IMAGE % {'width': width, 'height': height, 'data': data}
    outf.write(xml)