Skip to content

Commit 6112f89

Browse files
committed
Add examples
Signed-off-by: Brad Miller <[email protected]>
1 parent a252ded commit 6112f89

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

double.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
def double(oldimage):
3+
oldw = oldimage.getWidth()
4+
oldh = oldimage.getHeight()
5+
6+
newim = EmptyImage(oldw*2,oldh*2)
7+
8+
for row in range(newim.getWidth()): #// \label{lst:dib1}
9+
for col in range(newim.getHeight()): #// \label{lst:dib2}
10+
11+
originalCol = col//2 #// \label{lst:dib3}
12+
originalRow = row//2 #// \label{lst:dib4}
13+
oldpixel = oldimage.getPixel(originalCol,originalRow)
14+
15+
newim.setPixel(col,row,oldpixel)
16+
17+
return newim

grayscale.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from cImage import *
2+
3+
def grayPixel(p):
4+
avg = (p.getRed() + p.getGreen() + p.getBlue()) // 3
5+
return Pixel(avg,avg,avg)
6+
7+
def makeGrayScale(imageFile):
8+
myimagewindow = ImageWin("Image Processing",600,200)
9+
oldimage = FileImage(imageFile)
10+
oldimage.draw(myimagewindow)
11+
12+
width = oldimage.getWidth()
13+
height = oldimage.getHeight()
14+
newim = EmptyImage(width,height)
15+
16+
for row in range(height):
17+
for col in range(width):
18+
originalPixel = oldimage.getPixel(col,row)
19+
newPixel = grayPixel(originalPixel)
20+
newim.setPixel(col,row,newPixel)
21+
22+
newim.setPosition(width+1,0)
23+
newim.draw(myimagewindow)
24+
myimagewindow.exitOnClick()
25+
26+
makeGrayScale('lcastle.jpg')

lcastle.gif

14.9 KB
Loading

lcastle.jpg

4.3 KB
Loading

lcastle.png

28.2 KB
Loading

0 commit comments

Comments
 (0)