Python ImageChops类代码示例

本文整理汇总了Python中ImageChops的典型用法代码示例。如果您正苦于以下问题:Python ImageChops类的具体用法?Python ImageChops怎么用?Python ImageChops使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Python ImageChops类代码示例

在下文中一共展示了ImageChops类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: contrast

 def contrast(self, cropped_img):
        """
        Provides a high contrast board image for input into Tesseract OCR
        """

        # Convert the board image into greyscal

        bwImg = cropped_img.convert("L")

        # Multiply board image with inverted image so that text is black

        bwImgM = ImageChops.multiply(ImageChops.invert(bwImg), bwImg)

        # Increase contrast

        enhancedImg = ImageEnhance.Contrast(bwImgM)
        bwImgM = enhancedImg.enhance(5.0)

        # Produce pixel image object (array) for operation (operates in place)

        bwMDat = bwImgM.load()

        # If the pixel value is not black, make it white
        # (No colours any more, I want them to turn black)

        for i in range(0, bwImgM.size[1]):
            for j in range(0, bwImgM.size[0]):
                if bwMDat[j, i] != 0:
                    bwMDat[j, i] = 255
        # Debugging
        # bwImgM.show()

        return bwImgM
开发者ID:jamesmcm,项目名称:WWF-solver,代码行数:33,代码来源:PopBoard.py

示例2: Problem1ImageSolver

def Problem1ImageSolver():

	[dirImagesQuestions, dirImagesAnswers] = get_images_for_directory("Representations/Frames/Problem 1/")
	print "Problem 1 Image Questions: \n=================="
	compare_k = dirImagesQuestions.keys()[0]
	compare_v = dirImagesQuestions[compare_k]
	compare_v = ImageChops.invert(compare_v)
	compare_v = findRelevantBoxEdges(compare_v)
	# print compare_k
	for k,v in dirImagesQuestions.iteritems():
		temp_v = ImageChops.invert(dirImagesQuestions[k])
		temp_v = findRelevantBoxEdges(temp_v)
		image_equality = check_shape_equality(compare_v, temp_v)
		equality_string = ""
		if not image_equality:
			equality_string = "different"
		else:
			equality_string = "equal with " + image_equality[1] + " transformation"
		print str(k) + " and " + str(compare_k) + " are " + equality_string

	print "\nProblem 1 Image Answers: \n=================="
	for k,v in dirImagesAnswers.iteritems():
		temp_v = ImageChops.invert(dirImagesAnswers[k])
		temp_v = findRelevantBoxEdges(temp_v)
		# if compare_v.size != temp_v.size:
		# 	print str(compare_k) + " is " + str(compare_v.size) + " but " + str(k) + " is " + str(temp_v.size)
		image_equality = check_shape_equality(compare_v, temp_v)
		equality_string = ""
		if not image_equality:
			equality_string = "different"
		else:
			equality_string = "equal with " + image_equality[1] + " transformation"
		print str(k) + " and " + str(compare_k) + " are " + equality_string
开发者ID:daninus14,项目名称:cs4635-project1,代码行数:33,代码来源:ImageRepresentationExtractor.py

示例3: autofocus

 def autofocus(self,step=5000):
        if self.slide.pos[2] >= 0:  step = -step
        self.slide.moveZ(-step/2)
        z_start = self.slide.pos[2]
        self.frames.fillBuffer()
        self.slide.displaceZ(step)
        z_frames = self.frames.getBuffer()

        #sample every kth plus its lth neighbor:  for k=10,l=2 sample frame 0,10,20 and 2,12,22
        k = 10
        l = 2
        sample_ind = [ind*k for ind in range(len(z_frames)/k)]
        sample_ind2 = [ind*k+l for ind in range(len(z_frames)/k)]
        f = [z_frames[ind] for ind in sample_ind]
        f2 = [z_frames[ind] for ind in sample_ind2]
        n = len(f)
        diffs = []
        for i in range(n-2):
            diffs.append(ImageChops.difference(f[i],f2[i]))
        motion = []
        for f in diffs:
            f = ImageChops.multiply(f,self.curr_mask)
            motion.append(ImageStat.Stat(f).sum[0])
        #g = Gnuplot.Gnuplot()
        #g.plot(motion)

        max_frame = scipy.argmax(motion)
        max_focus = (max_frame/float(n))*step + z_start
        self.slide.moveZ(max_focus)
        return max_focus
开发者ID:cubular,项目名称:Drosophila-Project,代码行数:30,代码来源:detect.py

示例4: matchTemplate

def matchTemplate(searchImage, templateImage):
    minScore = -1000
    matching_xs = 0
    matching_ys = 0
    # convert images to "L" to reduce computation by factor 3 "RGB"->"L"
    searchImage = searchImage.convert(mode="L")
    templateImage = templateImage.convert(mode="L")
    searchWidth, searchHeight = searchImage.size
    templateWidth, templateHeight = templateImage.size
    # make a copy of templateImage and fill with color=1
    templateMask = Image.new(mode="L", size=templateImage.size, color=1)
    # loop over each pixel in the search image
    for xs in range(searchWidth - templateWidth + 1):
        for ys in range(searchHeight - templateHeight + 1):
            # for ys in range(10):
            # set some kind of score variable to "All equal"
            score = templateWidth * templateHeight
            # crop the part from searchImage
            searchCrop = searchImage.crop((xs, ys, xs + templateWidth, ys + templateHeight))
            diff = ImageChops.difference(templateImage, searchCrop)
            notequal = ImageChops.darker(diff, templateMask)
            countnotequal = sum(notequal.getdata())
            score -= countnotequal

            if minScore < score:
                minScore = score
                matching_xs = xs
                matching_ys = ys

    if minScore > 100:
        print "Location=", (matching_xs, matching_ys), "Score=", minScore
        quit()
开发者ID:pomeo,项目名称:hack-some-social-game,代码行数:32,代码来源:beeline.py

示例5: loadImage

 def loadImage(self, path):
        global zoomAmount, currentImage
        pixmap = QtGui.QPixmap(path)
        self.ui.image.setPixmap(pixmap)
        self.ui.image.setFixedSize(pixmap.size())

        self.zoomedPixmap = pixmap.scaled (self.ui.image.width()*zoomAmount, self.ui.image.height()*zoomAmount, QtCore.Qt.KeepAspectRatio)
        myPixmap = self.zoomedPixmap.copy(0,0, self.ui.zoomImage.width(), self.ui.zoomImage.height())
        self.ui.zoomImage.setPixmap(myPixmap)
        self.ui.zoomImage.setFixedSize(myPixmap.size())

        currentImage = Image.open(path)
        # convert to grayscale
        if currentImage.mode != "L":
            currentImage= currentImage.convert("L")
            
        # Sobel operator
        # edge1 = currentImage.filter(ImageFilter.Kernel((3,3), [1, 0, -1, 2, 0, -2, 1, 0, -1], scale=4))
        # edge2 = currentImage.filter(ImageFilter.Kernel((3,3), [1, 2, 1, 0, 0, 0, -1, -2, -1], scale=4))
        # edge3 = currentImage.filter(ImageFilter.Kernel((3,3), [-1, 0, 1, -2, 0, 2, -1, 0, 1], scale=4))
        # edge4 = currentImage.filter(ImageFilter.Kernel((3,3), [-1, -2, -1, 0, 0, 0, 1, 2, 1], scale=4))
        
        # Scharr operator
        edge1 = currentImage.filter(ImageFilter.Kernel((3,3), [3, 0, -3, 10, 0, -10, 3, 0, -3], scale=16))
        edge2 = currentImage.filter(ImageFilter.Kernel((3,3), [3, 10, 3, 0, 0, 0, -3, -10, -3], scale=16))
        edge3 = currentImage.filter(ImageFilter.Kernel((3,3), [-3, 0, 3, -10, 0, 10, -3, 0, 3], scale=16))
        edge4 = currentImage.filter(ImageFilter.Kernel((3,3), [-3, -10, -3, 0, 0, 0, 3, 10, 3], scale=16))
        
        currentImage = ImageChops.add(ImageChops.add(ImageChops.add(edge1, edge2), edge3), edge4)
开发者ID:Flipajs,项目名称:pilab-annotator,代码行数:29,代码来源:annotator.py

示例6: color_grad_magnitude

def color_grad_magnitude(image):
    red, green, blue = image.split()
    red_grad_mag = grad_magnitude(red)
    green_grad_mag = grad_magnitude(green)
    blue_grad_mag = grad_magnitude(blue)
    tmp_image = ImageChops.lighter(red_grad_mag, green_grad_mag)
    return ImageChops.lighter(tmp_image, blue_grad_mag)
开发者ID:matt-gardner,项目名称:pythonutil,代码行数:7,代码来源:image_utils.py

示例7: draw_line

def draw_line(image, point, neighbor, size):
    width, height = size
    center_point = (width//2, height//2)
    offset = (width//2 - point[0], height//2 - point[1])
    image = ImageChops.offset(image, offset[0], offset[1])
    draw = ImageDraw.Draw(image)
    to_point = ((neighbor[0] + offset[0]) % width, (neighbor[1] + offset[1]) % height)
    draw.line((center_point, to_point))
    return ImageChops.offset(image, -offset[0], -offset[1])
开发者ID:44hapa,项目名称:ants,代码行数:9,代码来源:McMaps.py

示例8: dilate

 def dilate(self, image):
     paddedImage = self.createPaddedImage(image, 1)
     thresholdImg = paddedImage.point(lambda i, v=128: i > v and 255)
     thresholdImg = ImageChops.invert(thresholdImg)
     filteredImg = thresholdImg.filter(ImageFilter.FIND_EDGES)
     thresholdImg = filteredImg.point(lambda i, v=128: i > v and 255)
     arithImg = ImageChops.add(paddedImage, thresholdImg)
     box = (1, 1, arithImg.size[0]-1, arithImg.size[1]-1)
     outImage = arithImg.crop(box)
     return outImage
开发者ID:CyberNAO,项目名称:naovita,代码行数:10,代码来源:SquareFinder.py

示例9: screen_mode

def screen_mode(im, wm, wmbuffer):
    imsize = im.size
    wmsize = wm.size
    brightness = float(_OPACITY) / 100
    brightval = int(round(255 * brightness))
    wm_pos = _wm_pos(wmbuffer, imsize, wmsize)
    black_bg = Image.new('RGB', imsize, (0, 0, 0) )
    black_bg.paste(wm, wm_pos)
    darkener = Image.new('RGB', imsize, (brightval, brightval, brightval) )
    darkened_fit_wm = ImageChops.multiply(black_bg, darkener)
    return ImageChops.screen(darkened_fit_wm, im)
开发者ID:tarekziade,项目名称:signpic,代码行数:11,代码来源:sign.py

示例10: addup

def addup(ims,offset):
	##must be of len 2**m
	n=1
	while len(ims)>1:
		newims=[]
		for i in range(0,len(ims),2):
			#print 'offset = %d'%(-offset*n)
			newims.append(ImageChops.add(ims[i],ImageChops.offset(ims[i+1],offset*n,0),2,0))
		ims = newims
		n*=2
	return ims[0]
开发者ID:mdonahoe,项目名称:personal,代码行数:11,代码来源:code.py

示例11: vignette

def vignette(image, off=0.2, stop=0.7, center_w=0.5, center_h=0.5):
	width, height = image.size
	vlayer = create_circular_gradient(image.size, 1.3, center_w, center_h, False)
	curv = list(curves.create_curve([(0, 0), (96, 200), (255, 255)]))
	vlayer = curves.apply_curves(vlayer, curv)
	vlayer = vlayer.filter(ImageFilter.BLUR).convert("RGB")
	clouds = create_clouds_bw(vlayer.size, 3)
	clouds = ImageEnhance.Brightness(clouds).enhance(3)
	clouds = ImageEnhance.Contrast(clouds).enhance(0.9)
	clouds = ImageChops.multiply(clouds, ImageChops.invert(vlayer))
	return ImageChops.multiply(image, ImageChops.invert(clouds))
开发者ID:KarolBedkowski,项目名称:photomagic,代码行数:11,代码来源:vignette.py

示例12: addup2

def addup2(ims,offset):
	##must be of len 2**m
	
	n=len(ims)+1
	#do all the offsets
	ims = [ImageChops.offset(im,-offset*(n/2-i),0) for i,im in enumerate(ims)]
	
	#add all the images, two at a time to avoid overflow
	while len(ims)>1:		
		ims = [ImageChops.add(ims[i],ims[i+1],2,0) for i in range(0,len(ims),2)]

	return ims[0]
开发者ID:mdonahoe,项目名称:personal,代码行数:12,代码来源:code.py

示例13: seg_mask

def seg_mask(iseries, sbinfilepath, segmaskfilepath, segsbfilepath,origfilepath,expfilepath,segexpfilepath,segorigfilepath):
	#iseries is a filename, without jpg on the end and with sb on the end
	# First, apply mask to sb image - mask is black (or grey) on white background
	filename = re.sub('_mask','',iseries) + '.jpg' #this is the sb image
	# print 'Initial', filename

	maskim = Image.open(segmaskfilepath+ re.sub('.jpg','_mask.jpg',filename)).convert("L")
	# Mask not always black so first make sure it is
	threshold = 141
	maskim = maskim.point(lambda p: p > threshold and 255)

	threshfilename = re.sub('_sb','_sbthres', filename)
	sbim = Image.open(sbinfilepath + threshfilename)
	try:
		# print 'Get thresh'
		seg_sb = ImageChops.lighter(sbim,maskim)
		seg_sb.save(segsbfilepath+ re.sub('.jpg','_seg.jpg',threshfilename) )
	except IOError:
		print 'error in file'

	#Now open the original image - get rid of sb from filename
	filename = re.sub('_sb','', filename)
	origim = Image.open(origfilepath + filename).convert("L")
	seg_orig = ImageChops.lighter(origim,maskim)
	seg_orig.save(segorigfilepath+ re.sub('.jpg','_seg_orig.jpg',filename))

	#Now open the exp image and apply mask
	# First make mask white on black
	maskim = ImageChops.invert(maskim)

	# Now extract all the pixels that are white and make this region a transparent region on the mask
	maskim = maskim.convert('LA')
	datas = maskim.getdata()
	newData = list()
	for item in datas:
		if item[0] == 255:
			newData.append((255, 0))
		else:
			newData.append(item)

	maskim.putdata(newData)
	#img.save("img2.png", "PNG")
	l,a = maskim.split()

	# Check that exp file exists
	if os.path.exists(expfilepath +  re.sub('ish','exp',filename)):
		#seg_exp = ImageChops.logical_and(expim,maskim)
		expim = Image.open(expfilepath +  re.sub('ish','exp',filename)).convert("LA") # should be a grayscale image
		expim.paste(maskim, mask = a)
		expim = expim.convert("L")
		expim.save(segexpfilepath+ re.sub('.jpg','_seg_exp.tif',filename))
	else: print 'N'
开发者ID:MattNolanLab,项目名称:Ramsden_MEC,代码行数:52,代码来源:ABA_imageprocessing.py

示例14: combine

def combine(ims,offset):
	
	n=len(ims)-1
	
	#do all the offsets
	ims = [ImageChops.offset(im,-offset*(n/2-i),0) for i,im in enumerate(ims)]
	
	#add all the images, two at a time to avoid overflow
	while len(ims)>1:		
		ims = [ImageChops.add(ims[i],ims[i+1],2,0) for i in range(0,len(ims),2)]
	
	#return the final result image
	return ims[0]
开发者ID:mdonahoe,项目名称:personal,代码行数:13,代码来源:shiftadd.py

示例15: _gen_pants

 def _gen_pants(self):
     if self.command.has_key("pants"):
         self.base_image = self.image["pants"]
         self.pattern_image = self.image[self.command["pants"]]
     if self.command.has_key("color"):
         self.color_image = Image.new("RGBA", (240, 240), self.command["color"])
     if self.command.has_key("base_color"):
         self.base_color_image = Image.new("RGBA", (240, 240), self.command["base_color"])
     
     self.icon.paste(self.base_image, mask=self.base_image)
     self.icon = ImageChops.composite(self.icon, self.base_color_image, self.image["base_mask"])
     self.icon = ImageChops.composite(self.icon, self.color_image, self.pattern_image)
     self.icon.paste(self.image["frame"], mask=self.image["frame"])
开发者ID:non117,项目名称:Shima,代码行数:13,代码来源:shima.py

本文标签属性:

示例:示例是什么意思

代码:代码零九

Python:python菜鸟教程

上一篇:C++ MENU_ITEM函数代码示例
下一篇:C++ Chit::GetItem方法代码示例

为您推荐