Esempio n. 1
0
def borderresize(filename, infolderpath, runtype):
	'''
	Resize ISH images
	:param filename:
	:param infolderpath:
	:return:
	'''
	newimagewidth = 6000/4
	newimageheight = 4500/4

	if 'ishfull' in filename: newimage = Image.new('L', (newimagewidth,newimageheight), (255) ) #white image
	else:newimage = Image.new('L', (newimagewidth,newimageheight), (0) ) #black image
	resizefactor = 1.25 # images 0.8 of original size
	try:
		ishimage = Image.open(infolderpath +filename).convert("L")
	except IOError:
		print filename, 'Image failed'
		return

	# Not used previously - remove outer border to get rid of any dark borders on original image
	ishimage = ImageOps.crop(ishimage, border=5)

	dwidth = newimagewidth - ishimage.size[0]
	dheight = newimageheight - ishimage.size[1]
	newimage.paste(ishimage, (dwidth/2,dheight/2,dwidth/2+ishimage.size[0],dheight/2+ishimage.size[1]))
	newimage = newimage.resize((int(float(newimagewidth)/resizefactor),int(float(newimageheight)/resizefactor)))
	newimage.save(re.sub('Original_%s' % runtype,'Resize_%s' % runtype, infolderpath) + filename)
Esempio n. 2
0
def crop(image, mode=None, all=0, left=0, right=0, top=0, bottom=0):
    if mode == _t('Auto'):
        image = auto_crop(image)
    elif mode == _t('All'):
        image = ImageOps.crop(image, border=all)
    else:
        w, h = image.size
        box = (left, top, w - right, h - bottom)
        image = image.crop(box)
    return image
Esempio n. 3
0
def crop(image, mode=None, all=0, left=0, right=0, top=0, bottom=0):
    if mode == _t('Auto'):
        image = auto_crop(image)
    elif mode == _t('All'):
        image = ImageOps.crop(image, border=all)
    else:
        w, h = image.size
        box = (
            left,
            top,
            w - right,
            h - bottom)
        image = image.crop(box)
    return image
Esempio n. 4
0
    def run(self):
        while True:

            # get out user defined border
            border = self.get_parameter('border')

            # for each document waiting on our input port
            for doc in self.receive_all('in'):
                try:
                    # grab the serialized image
                    raw_image = doc.get('image_data')

                    # grab the meta-data we need
                    size = doc.get_meta('size', 'image_data')
                    mode = doc.get_meta('mode', 'image_data')

                    # deserialize the image content
                    image = Image.fromstring(mode, size, raw_image)

                    # perform the cropping using our user defined border
                    try:
                        border = int(border)
                    except:
                        border = DEFAULT_BORDER
                    cropped_image = ImageOps.crop(image, border)

                    # update the meta-data for the image
                    doc.set_meta('size', cropped_image.size, 'image_data')
                    doc.set_meta('mode', cropped_image.mode, 'image_data')

                    # update the image_data with the new serialized payload
                    doc.set('image_data', cropped_image.tostring())

                except Exception as e:
                    log.error('Component Failed: %s' % self.__class__.__name__)
                    log.error('Reason: %s' % str(e))
                    log.debug(traceback.print_exc())

                # send the document to the next component
                self.send('out', doc)

            # yield the CPU
            self.yield_ctrl()
Esempio n. 5
0
    def run(self):
        while True:

            # get out user defined border
            border = self.get_parameter('border')

            # for each document waiting on our input port
            for doc in self.receive_all('in'):
                try:
                    # grab the serialized image
                    raw_image = doc.get('image_data')

                    # grab the meta-data we need
                    size = doc.get_meta('size', 'image_data')
                    mode = doc.get_meta('mode', 'image_data')

                    # deserialize the image content
                    image = Image.fromstring(mode, size, raw_image)

                    # perform the cropping using our user defined border
                    try:
                        border = int(border)
                    except:
                        border = DEFAULT_BORDER
                    cropped_image = ImageOps.crop(image, border)

                    # update the meta-data for the image
                    doc.set_meta('size', cropped_image.size, 'image_data')
                    doc.set_meta('mode', cropped_image.mode, 'image_data')

                    # update the image_data with the new serialized payload
                    doc.set('image_data', cropped_image.tostring())

                except Exception as e:
                    log.error('Component Failed: %s' % self.__class__.__name__)
                    log.error('Reason: %s' % str(e))                    
                    log.debug(traceback.print_exc())

                # send the document to the next component
                self.send('out', doc)

            # yield the CPU
            self.yield_ctrl()
Esempio n. 6
0
def postProcessing(pic_name, imsize, labels, profile_save_path):
    labels = denoise(labels)
    labels = 1 - labels
    labels = denoise(labels)
    labels = 1 - labels

    h = imsize[1]
    w = int(h * 0.75)
    im = Image.fromarray(np.uint8(labels * 255).reshape(80, 60))
    im = im.convert('RGB')
    im = im.resize((w, h), Image.ANTIALIAS)
    background = Image.new('L', imsize, 'white')

    left_border = (w - imsize[0] + 1) / 2
    if left_border > 0:
        im = ImageOps.crop(im, border=(left_border, 0))
        background.paste(im, (0, 0))
    else:
        background.paste(im, (-left_border, 0))
    background.save(profile_save_path + pic_name + '-profile.jpg')
Esempio n. 7
0
            mask = Image.new("L", (newsize, newsize), bg_color)
        x_noise = y_noise = 0
        for it in xrange(jitter_count):
            x0 = (newsize - bw.size[0]) / 2 + x_noise
            y0 = (newsize - bw.size[1]) / 2 + y_noise
            x1 = x0 + bw.size[0]
            y1 = y0 + bw.size[1]
            x = (x0, y0, x1, y1)
            offset = 20
            x_ = (x0 + offset, y0 + offset, x1 + offset, y1 + offset)
            mask = ImageOps.expand(mask, offset, fill=bg_color)
            mask.paste(bw, x_)
            for i in xrange(20):
                mask = mask.filter(ImageFilter.SMOOTH)
                mask.paste(bw, x_)
            mask = ImageOps.crop(mask, offset)
            newdata = np.array(mask.getdata()).T.flatten().copy()
            #mask.show()
            #pdb.set_trace()
            #plt.imshow(np.array(mask.getdata()).reshape(newsize,newsize,3))
            #plt.show()
            data.append(newdata)
            labels.append(label)
            x_noise, y_noise = np.random.normal(0, 5, 2)
            x_noise = max(-20, min(x_noise, 20))
            y_noise = max(-20, min(y_noise, 20))

if color:
    np.save("caltech_30_color", data)
else:
    np.save("caltech_30_gray", data)
Esempio n. 8
0
            mask=Image.new("L",(newsize,newsize),bg_color)
        x_noise= y_noise=0
        for it in xrange(jitter_count):
            x0=(newsize-bw.size[0])/2+x_noise
            y0=(newsize-bw.size[1])/2+y_noise
            x1=x0+bw.size[0]
            y1=y0+bw.size[1]
            x = (x0,y0,x1,y1)
            offset=20
            x_ = (x0+offset,y0+offset,x1+offset,y1+offset)
            mask=ImageOps.expand(mask,offset,fill=bg_color)
            mask.paste(bw,x_)
            for i in xrange(20):
                mask=mask.filter(ImageFilter.SMOOTH)
                mask.paste(bw,x_)
            mask=ImageOps.crop(mask,offset)
            newdata=np.array(mask.getdata()).T.flatten().copy()
            #mask.show()
            #pdb.set_trace()
            #plt.imshow(np.array(mask.getdata()).reshape(newsize,newsize,3))
            #plt.show()
            data.append(newdata)
            labels.append(label)
            x_noise,y_noise=np.random.normal(0,5,2)
            x_noise=max(-20,min(x_noise,20))
            y_noise=max(-20,min(y_noise,20))

if color:
    np.save("caltech_30_color",data)
else:
    np.save("caltech_30_gray",data)
Esempio n. 9
0
 def Cropborder(self, Button):      
     self.p = Image.open(self.Newpath)
     self.border = self.border + 10
     self.s = ImageOps.crop(self.p, self.border)
     self.s.show()
     self.s.save(self.Newpath)