Dip Lab
Dip Lab
.pale e: Refers to a set of colors used by the image. In formats like GIF or PNG, each pixel is
represented by an index poin ng to a color in the pale e.
.resize(()): Resizes the image. This does not maintain the aspect ra o automa cally unless
explicitly handled. Use when you need a specific size.
.thumbnail(()): Resizes the image to fit within a defined size while maintaining the aspect
ra o.
.crop((x,y,z,w)): Crops the image to the defined rectangle (from le , top, right, bo om).
import numpy as np
final = Image.fromarray(img_final)
Image Sampling
Image sampling refers to represen ng a con nuous image as a discrete set of pixel values. This can
involve downsampling (reducing resolu on) through resizing.
Resizing Methods
import numpy as np
original_image = Image.open(image_path)
original_image_array = np.array(original_image)
for i in range(target_height):
for j in range(target_width):
resized_image = Image.fromarray(resized_image_array)
return resized_image
# Example usage:
image_path = "image.jpg"
target_height = 100
target_width = 100
resized_image.save("custom_resized_image.jpg")
resized_image.show()
Quan za on of Images
gray_img = img.convert("L")
img_array = np.array(gray_img)
N4 (4-connected): Refers to the set of 4 immediate neighboring pixels in a grid (up, down,
le , right).
m_adj_pixels = []
if (pixel_value in n4p) or (pixel_value in ndp and np.intersect1d(n4p, n4(img, i, j)) and all(val is
not None and val not in range(256) for val in np.intersect1d(n4p, n4(img, i, j)))):
m_adj_pixels.append((i, j))
return m_adj_pixels