楼主: ReneeBK
974 4

cImage - A simple image processing library for Python [推广有奖]

  • 1关注
  • 62粉丝

VIP

学术权威

14%

还不是VIP/贵宾

-

TA的文库  其他...

R资源总汇

Panel Data Analysis

Experimental Design

威望
1
论坛币
49517 个
通用积分
53.5804
学术水平
370 点
热心指数
273 点
信用等级
335 点
经验
57815 点
帖子
4006
精华
21
在线时间
582 小时
注册时间
2005-5-8
最后登录
2023-11-26

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

cImage - A simple image processing library for Python


本帖隐藏的内容

cImage-master.zip (55.9 KB)


Installation

copy cImage.py to your site-packages directory.

Usage

This image library is not going to give you fancy high performance operations on images. It allows you to read in an image and manipulate its pixels. Then you can save the new image to a file, or you can display the image in a window. Thats really about it, but its really all you want to do if you are teaching an introductory computer science course.

Image Types Supported

If you have PIL installed on your system:

  • jpeg
  • gif
  • tiff
  • png
  • etc.

If you do not have PIL installed then you are stuck with GIF images only.

If you are using Python 2.6/2.7 I recommend you install Pillow its a simple fork of PIL that you can install with easy_install or pip.

If you are using Python 3 You can get a working version of PIL Here: https://pypi.python.org/pypi/Pillow/2.0.0

Note that if you scroll down to the bottom you will find binary installations for Windows. Linux and Mac users can follow the instructions on the page.

  1. Example

  2. from cImage import *
  3. myimagewindow = ImageWin("Image Processing",600,300)
  4. oldimage = FileImage("lutherbell.jpg")
  5. oldimage.setPosition(0,0)
  6. oldimage.draw(myimagewindow)

  7. width = oldimage.getWidth()
  8. height = oldimage.getHeight()
  9. newim = EmptyImage(width,height)

  10. for row in range(height):
  11.     for col in range(width):
  12.             oldpixel = oldimage.getPixel(col,row)
  13.             ave=(oldpixel.getRed()+oldpixel.getGreen()+oldpixel.getBlue())/3
  14.             newim.setPixel(col,row,Pixel(ave,ave,ave))

  15. newim.setPosition(width+1,0)
  16. newim.draw(myimagewindow)

  17. myimagewindow.exitOnClick()
复制代码


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Processing processI Library Process python library simple

本帖被以下文库推荐

沙发
ReneeBK 发表于 2016-9-12 07:55:57 |只看作者 |坛友微信交流群
  1. import cImage as image

  2. img = image.Image("lcastle.gif")
  3. newimg = image.EmptyImage(img.getWidth(),img.getHeight())
  4. win = image.ImageWin()

  5. for col in range(img.getWidth()):
  6.     for row in range(img.getHeight()):
  7.        p = img.getPixel(col,row)

  8.        newred = 255-p.getRed()
  9.        newgreen = 255-p.getGreen()
  10.        newblue = 255-p.getBlue()

  11.        newpixel = image.Pixel(newred,newgreen,newblue)

  12.        newimg.setPixel(col,row,newpixel)

  13. newimg.draw(win)
  14. win.exitonclick()
复制代码

使用道具

藤椅
ReneeBK 发表于 2016-9-12 07:57:13 |只看作者 |坛友微信交流群
  1.    
  2. def double(oldimage):
  3.     oldw = oldimage.getWidth()
  4.     oldh = oldimage.getHeight()

  5.     newim = EmptyImage(oldw*2,oldh*2)

  6.     for row in range(newim.getWidth()):   #// \label{lst:dib1}
  7.         for col in range(newim.getHeight()): #// \label{lst:dib2}
  8.             
  9.             originalCol = col//2  #// \label{lst:dib3}
  10.             originalRow = row//2  #// \label{lst:dib4}
  11.             oldpixel = oldimage.getPixel(originalCol,originalRow)

  12.             newim.setPixel(col,row,oldpixel)

  13.     return newim
复制代码

使用道具

板凳
ReneeBK 发表于 2016-9-12 07:58:09 |只看作者 |坛友微信交流群
  1. from cImage import *

  2. def grayPixel(p):
  3.     avg = (p.getRed() + p.getGreen() + p.getBlue()) // 3
  4.     return Pixel(avg,avg,avg)

  5. def makeGrayScale(imageFile):
  6.     myimagewindow = ImageWin("Image Processing",600,200)
  7.     oldimage = Image(imageFile)            
  8.     oldimage.draw(myimagewindow)

  9.     width = oldimage.getWidth()
  10.     height = oldimage.getHeight()
  11.     newim = EmptyImage(width,height)

  12.     for row in range(height):
  13.         for col in range(width):
  14.             originalPixel = oldimage.getPixel(col,row)
  15.             newPixel = grayPixel(originalPixel)
  16.             newim.setPixel(col,row,newPixel)

  17.     newim.setPosition(width+1,0)
  18.     newim.draw(myimagewindow)
  19.     myimagewindow.exitOnClick()

  20. makeGrayScale('lcastle.gif')
复制代码

使用道具

报纸
ReneeBK 发表于 2016-9-12 08:00:40 |只看作者 |坛友微信交流群
  1. from setuptools import setup

  2. #with open('requirements.txt', 'r') as fh:
  3. #    dependencies = [l.strip() for l in fh]

  4. setup(
  5.     name='cImage',
  6.     description='Image manipulation library for media computation education',
  7.     version='1.4.1',
  8.     py_modules = ['cImage'],
  9.     author = 'Brad Miller',
  10.     author_email = 'bonelake@mac.com',
  11.     install_requires= ['Pillow==2.9.0'],
  12.     include_package_data = False,
  13.     license='GPL',
  14.     url = 'https://github.com/bnmnetp/cImage',
  15.     keywords = ['image', 'education'], # arbitrary keywords
  16.     classifiers=('Development Status :: 5 - Production/Stable',
  17.                    'Environment :: Console',
  18.                    'Intended Audience :: Education',
  19.                    'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
  20.                    'Operating System :: MacOS',
  21.                    'Operating System :: Unix',
  22.                    'Programming Language :: Python',
  23.                    'Programming Language :: Python :: 2.7',
  24.                    'Programming Language :: Python :: 3.4',
  25.                    'Topic :: Education'),
  26.     long_description=open('README.rst').read(),
  27. )
复制代码

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-11-6 07:22