当前位置: 首页>>代码示例>>Python>>正文


Python Image.open方法代码示例

本文整理汇总了Python中Image.Image.open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.open方法的具体用法?Python Image.open怎么用?Python Image.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Image.Image的用法示例。


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

示例1: convert2

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
def convert2(path):
    image=Image.open(path)
    out = os.path.splitext(path)[0] + ".png"
    non_transparent=Image.new('RGBA', image.size, (255,255,255,255))
    non_transparent.paste(image,(0,0),image)
    #non_transparent.paste(image,image)
    non_transparent.save(out)
开发者ID:licface,项目名称:chm2webcmd,代码行数:9,代码来源:ico2png.py

示例2: convert

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
def convert(path):
    from PIL import Image

    out = os.path.splitext(path)[0] + ".png"
    im = Image.open(path)
    bg = Image.new("RGB", im.size, (255,255,255))
    bg.paste(im,im)
    bg.save(out)
开发者ID:licface,项目名称:chm2webcmd,代码行数:10,代码来源:ico2png.py

示例3: test_accessor_methods

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
 def test_accessor_methods(self):
     self.assertEquals(self.pl.get_test_photosize(), self.s)
     self.assertEquals(self.pl.get_test_size(),
                       Image.open(self.pl.get_test_filename()).size)
     self.assertEquals(self.pl.get_test_url(),
                       self.pl.cache_url() + '/' + \
                       self.pl._get_filename_for_size(self.s))
     self.assertEquals(self.pl.get_test_filename(),
                       os.path.join(self.pl.cache_path(),
                       self.pl._get_filename_for_size(self.s)))
开发者ID:cattias,项目名称:cannesalair,代码行数:12,代码来源:tests.py

示例4: GenThumb

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
    def GenThumb(self, size=160):
        """Generate a thumbnail for the image"""
        tempdir = tempfile.mkdtemp()
        sub = subprocess.Popen([mplayer, self.fullPath, "-vo", "jpeg:outdir=%s" % tempdir, "-ao", "null", "-frames", "1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        sub.wait()
        listThumb = [os.path.join(tempdir, i) for i in os.listdir(tempdir)]
        if len(listThumb) != 1:
            print ("Unexpected result ... have a look at %s ther should only be one jpeg image" % tempdir)
        self.thumbName = OP.splitext(self.fullPath)[0] + "--Thumb.jpg"
        img = Image.open(listThumb[0])
        img.thumbnail((size, size))
        img.save(self.thumbName)
#        sub = subprocess.Popen(["%s -geometry %ix%i %s/*.jpg %s" % (convert, size, size, tempdir, self.thumbName))
        for i in listThumb:
            os.remove(i)
        os.rmdir(tempdir)
开发者ID:objects-in-space-and-time,项目名称:imagizer,代码行数:18,代码来源:NommeVideo.py

示例5: _to_png

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
def _to_png(path):
    for infile in sys.argv[1:]:
        outfile = os.path.splitext(infile)[0] + ".png"
        if infile != outfile:
            try:
                im = Image.open(infile)
                im = im.convert("RGBA")
                datas = im.load()

                for i in xrange(im.size[1]):
                    for x in xrange(im.size[0]):
                        if datas[x, i] == (255, 255, 255, 255):
                            #print "i =", i
                            #print "x =", x
                            datas[x, i] = (255, 255, 255, 0)
                
                im.save(outfile, "PNG")
            except IOError:
                print "cannot create thumbnail for", infile
开发者ID:licface,项目名称:chm2webcmd,代码行数:21,代码来源:ico2png.py

示例6: to_png

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
def to_png(path):
    for infile in sys.argv[1:]:
        outfile = os.path.splitext(infile)[0] + ".png"
        if infile != outfile:
            try:
                im = Image.open(infile)
                im = im.convert("RGBA")
                datas = im.getdata()
                print "datas =", datas
                newData = []
                for i in datas:
                    if i[0] == 255 and i[1] == 255 and i[2] == 255:
                        print "i =", i
                        newData.append((255, 255, 255, 0))
                    else:
                        newData.append(i)
                im.putdata(newData)
                im.save(outfile, "PNG")
            except IOError:
                print "cannot create thumbnail for", infile
开发者ID:licface,项目名称:chm2webcmd,代码行数:22,代码来源:ico2png.py

示例7: main

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
def main(args):
	try:

		# Initializing 
		init = pyossimtest.Init.instance()
		init.initialize()


		#Input and open image file
		imageFileName = raw_input()
		img = Image()

		if img.open(imageFileName):
			print "Opened: " + str(imageFileName)

		# Display bands selection
		bands = list()
		bands = img.getBandSelection()
		print bands

		if bands is not None:
			i = 0
			for i in range(0, len(bands)):
				print "band[" + i + "]: " + bands[i]

			i = 0
			for i in range(0, len(bands)):
				bands[i] = len(bands) - i + 1

			img.selectBands(bands)

		else:
			print "Image.getBandSelection returned Null"


		#Set the histogram
		ext = str("his")
		im = imageFileName.split('.')
		im[0] = im[0] + ext
		his = str(im[0])
	
		if img.setHistogram(his):
			his2 = img.getHistogramFile()
			print "Image.getHistogramFile() result: " + his2
		else:
			print "Image.getHistogramFile() returned false!"
	

		#Set the overview
		ext = str("ovr")
		im = imageFileName.split('.')
		im[0] = im[0] + ext
		ovr = str(im[0])
	
		if img.setOverview(ovr):
			ovr2 = img.getOverviewFile()
			print "Image.getOverviewFile() result: " + ovr2
		else:
			print "Image.getOverviewFile() returned false!"
	
	
	except(Exception):
		print "Caught Exception"
开发者ID:renyu310,项目名称:ossim-svn,代码行数:65,代码来源:ossimImageTest.py

示例8: FImage

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
    cv.DFT(iMat,mFFT,cv.CV_DXT_FORWARD)
    return mFFT

def FImage(mat):
    w = mat.cols
    h = mat.rows
    size = (w,h)
    iAdd = cv.CreateImage(size,cv.IPL_DEPTH_8U,1)
    for i in range(h):
        for j in range(w):
            iAdd[i,j] = mat[i,j][1]/h + mat[i,j][0]/h
    return iAdd

def fun(filename):
    image = cv.LoadImage(filename,0)    
    mAfterFFT = FFT(image)
    mBeginFFT = FFT(image,1)
    iAfter = FImage(mAfterFFT)
    iBegin = FImage(mBeginFFT)
#   cv.ShowImage('image',image)
#   cv.ShowImage('iAfter',iAfter)
#   cv.ShowImage('iBegin',iBegin)
#   cv.WaitKey(0)
    cv.SaveImage(outname, iAfter)
    return outname

if __name__ == '__main__':
    fun('/home/townboy/lena.ppm')
    Image.open(outname).show()

开发者ID:townboy,项目名称:junk_code,代码行数:31,代码来源:fuf.py

示例9:

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
import Image.Image as Image
import numpy as np
import sys

threshold=100
dist=5
img=Image.open(sys.argv[1]).convert('RGBA')
# np.asarray(img) is read only. Wrap it in np.array to make it modifiable.
arr=np.array(np.asarray(img))
r,g,b,a=np.rollaxis(arr,axis=-1)    
#mask=((r>threshold)
#      & (g>threshold)
#      & (b>threshold)
#      & (np.abs(r-g)<dist)
#      & (np.abs(r-b)<dist)
#      & (np.abs(g-b)<dist)
#      )
mask=((r==255)&(g==255)&(b==255)).T
arr[mask,3]=0
img=Image.fromarray(arr,mode='RGBA')
img.save('out.png')
开发者ID:licface,项目名称:chm2webcmd,代码行数:23,代码来源:convert_001.py

示例10: test

# 需要导入模块: from Image import Image [as 别名]
# 或者: from Image.Image import open [as 别名]
 def test(self):
     effect = PhotoEffect(name='test')
     im = Image.open(self.pl.image.path)
     self.assert_(isinstance(effect.pre_process(im), Image.Image))
     self.assert_(isinstance(effect.post_process(im), Image.Image))
     self.assert_(isinstance(effect.process(im), Image.Image))
开发者ID:cattias,项目名称:cannesalair,代码行数:8,代码来源:tests.py


注:本文中的Image.Image.open方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。