Professional Documents
Culture Documents
Activity-2 Group4 Ang, Reyes
Activity-2 Group4 Ang, Reyes
ACTIVITY 2:
PROCESS A SINGLE IMAGE WITH
PILLOW
ELECTIVE 3 LABORATORY
CPE 0332.1-3
By:
GROUP 4:
ANG, JV B.
REYES, Martin Antonio M.
Submitted to
MA’AM EVELYN B. CAROLINO
Used Photo/Image:
RESIZING
OUTPUT/Documentation:
RESAMPLING METHODS
OUTPUT/Documentation:
CONVERTING TO BITONAL
OUTPUT/Documentation:
Figure 11: Converting to Bitonal Results in VS Code (Jupyter Type File)
THRESHOLD FOR BITONAL
OUTPUT/Documentation:
Figure 12: Threshold for Bitonal Results in VS Code (Jupyter Type File)
IMAGE PAGE TO BITONAL
OUTPUT/Documentation:
Figure 13: Image Page to Bitonal Results in VS Code (Jupyter Type File)
GROUP DOCUMENTATION
Full Syntax Code:
Creating Libraries
#imports
from PIL import Image
from pathlib import Path
import matplotlib.pyplot as plt
#opening img
img = Image.open("C:\Downloads\ELEC LAB\ACT 2\TWICESUPREMACY.jpg")
%matplotlib inline
plt.rcParams["figure.figsize"]=(20,12)
%config InlineBackline.figure_format='retina'
current_directory = Path.cwd()
img_path = current_directory.joinpath("C:\Downloads\ELEC LAB\ACT 2\TWICESUPREMACY.jpg")
print(f'current_directory:{current_directory}')
print(f'img_path:{img_path}')
Image Rotation
#rotation
rotated_image = image.rotate(23)
plt.imshow(rotated_image)
rotated_image = image.rotate(-23,resample=Image.BICUBIC,expand=True)
plt.imshow(rotated_image)
Resizing Image
#resizing
image_resized = image.resize((500,500))
plt.imshow(image_resized)
Creating Thumbnail
#thumbnail
thumbnail = image.copy()
thumbnail.thumbnail((500,500))
plt.imshow(thumbnail)
Resampling Methods
resample_dictionary = {'Nearest Neighbor':Image.NEAREST, 'Bilinear 2x2':Image.BILINEAR, 'Bicubic
4x4':Image.BICUBIC}
for name in resample_dictionary:
print(name)
resample_method = resample_dictionary[name]
%timeit rotated_image = image_resized.rotate(-23,resample=resample_method,expand=True)
Cropping Image
image_cropped = image.crop(box=(0,0,500,500))
plt.imshow(image_cropped)
image_cropped = image.crop(box=(200,210,500,500))
print(f'width:{image_cropped.size[0]}')
print(f'height:{image_cropped.size[1]}')
plt.imshow(image_cropped)
RGB Channels
#RGB channels
red_channel,green_channel,blue_channel = image_cropped.split()
figure,(red,green,blue) = plt.subplots(ncols=3,figsize=(18,8))
red.imshow(red_channel)
red.set_title("Red Channel")
green.imshow(green_channel)
green.set_title("Green Channel")
blue.imshow(blue_channel)
blue.set_title("Blue Channel")
plt.tight_layout()
color_bar = image_cropped.crop(box=[0,100,250,250])
plt.imshow(color_bar)
red_channel,green_channel,blue_channel = color_bar.split()
figure,(color,red,green,blue) = plt.subplots(nrows=4,figsize=(20,15))
color.imshow(color_bar)
color.set_xticks([]), color.set_yticks([])
color.set_title("RGB Image")
red.imshow(red_channel)
red.set_xticks([]), red.set_yticks([])
red.set_title("Red Channel")
green.imshow(green_channel)
green.set_xticks([]), green.set_yticks([])
green.set_title("Green Channel")
blue.imshow(blue_channel)
blue.set_xticks([]), blue.set_yticks([])
blue.set_title("Blue Channel")
plt.tight_layout()
Converting to Grayscale
#converting to grayscale
image_grayscale = color_bar.convert(mode='L')
plt.rcParams["figure.figsize"]=(20,12)
plt.imshow(image_grayscale)
Converting to Bitonal
#converting to bitonal
image_bitonal_floyd_steinberg = image_grayscale.convert(mode='1')
image_bitonal_no_dithering = image_grayscale.convert(mode='1',dither=Image.NONE)
plt.figure()
plt.imshow(image_grayscale)
plt.figure()
plt.imshow(image_bitonal_floyd_steinberg)
plt.figure()
plt.imshow(image_bitonal_no_dithering)
threshold = 120
image_bitonal_120 = image_grayscale.point(lambda pixel: pixel>threshold and 255)
plt.figure()
plt.imshow(image_bitonal_120)