Docsity

BCA DIGITAL IMAGE PROCESSING LAB ASSIGNMENT WITH CODE AND OUTPUT, Assignments of Digital Image Processing

Toggle sidebar
bg1
Assignment no:- 01 Date:-
Write a program (in python) to read and display an image.
Program:-
# Upload image file
from google.colab import files
import cv2
import matplotlib.pyplot as plt
uploaded = files.upload()
# Automatically read uploaded image
for filename in uploaded.keys():
img = cv2.imread(filename)
if img is None:
print("Image not loaded.")
else:
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
plt.imshow(img)
plt.axis('off')
plt.show()
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download BCA DIGITAL IMAGE PROCESSING LAB ASSIGNMENT WITH CODE AND OUTPUT and more Assignments Digital Image Processing in PDF only on Docsity!

Assignment no:- 01 Date:- Write a program (in python) to read and display an image. Program:-

Upload image file

from google.colab import files import cv import matplotlib.pyplot as plt uploaded = files.upload()

Automatically read uploaded image

for filename in uploaded.keys(): img = cv2.imread(filename) if img is None: print("Image not loaded.") else: img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) plt.imshow(img) plt.axis('off') plt.show()

Input/Output Signature:-………………………………….

Input/Output Signaute:-……………………………….

Assignment no:- 03 Date:- Write a program (in python) to read, show, and print the properties of an image. Program:-

Upload image file

from google.colab import files import cv import matplotlib.pyplot as plt uploaded = files.upload()

Automatically read uploaded image

for filename in uploaded.keys():

Read image

img = cv2.imread(filename)

Show image

img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) plt.imshow(img_rgb) plt.axis('off') plt.title("Input Image") plt.show()

Print image properties

print("Image Name:", filename) print("Image Shape (Height, Width, Channels):", img.shape) print("Image Height:", img.shape[0]) print("Image Width :", img.shape[1]) print("Number of Channels:", img.shape[2]) print("Image Size (Total Pixels) :", img.size) print("Image Data Type:", img.dtype)

Assignment no:- 04 Date:- Write a program (in python) to enlarge an image. Program:-

Upload image

from google.colab import files import cv from google.colab.patches import cv2_imshow uploaded = files.upload()

Read and enlarge image

for filename in uploaded.keys(): img = cv2.imread(filename)

Enlarge image (2 times bigger)

enlarged = cv2.resize(img, None, fx=2, fy=2, interpolation=cv2.INTER_LINEAR)

Show images

print("Original Image") cv2_imshow(img) print("Enlarged Image") cv2_imshow(enlarged)

Save enlarged image

cv2.imwrite("enlarged_image.jpg", enlarged)

Input/Output Signature:-………………………………….

Input/Output Signature:-………………………………

Assignment no:- 06 Date:- Write a program (in Python) to implement Color conversion for RGB model to gray scale model. Program:-

Upload image

from google.colab import files import cv from google.colab.patches import cv2_imshow uploaded = files.upload()

Read and convert image

for filename in uploaded.keys():

Read image

img = cv2.imread(filename)

Convert RGB image to Gray scale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Show images

print("Original Image") cv2_imshow(img) print("Gray Scale Image") cv2_imshow(gray)

Save gray image

cv2.imwrite("gray_image.jpg", gray)

Assignment no:- 07 Date:- Write a program (in python) to perform Histogram Equalization. Program:-

Upload image

from google.colab import files import cv from google.colab.patches import cv2_imshow uploaded = files.upload()

Read and process image

for filename in uploaded.keys():

Read image

img = cv2.imread(filename)

Convert to Gray scale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Apply Histogram Equalization

equalized = cv2.equalizeHist(gray)

Show images

print("Original Image") cv2_imshow(img) print("Gray Scale Image") cv2_imshow(gray) print("Histogram Equalized Image") cv2_imshow(equalized)

Save output

cv2.imwrite("equalized_image.jpg", equalized)

Input/Output Signature:-……………………………………………

Input/Output Signature:-………………………………

Assignment no:- 09 Date:- Write a program (in python) to implement Sharpening (Laplacian Spatial Filters). Program:-

Upload image

from google.colab import files import cv from google.colab.patches import cv2_imshow uploaded = files.upload()

Read and process image

for filename in uploaded.keys():

Read image

img = cv2.imread(filename)

Convert to Gray scale

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

Apply Laplacian filter

laplacian = cv2.Laplacian(gray, cv2.CV_64F)

Sharpen image

sharpened = cv2.convertScaleAbs(gray - laplacian)

Show images

print("Original Image") cv2_imshow(img)

Input/Output Signature:-………………..

Assignment no:- 10 Date:- Write a program (in python) for Smoothing and Sharpening on a color image. Program:-

Upload image

from google.colab import files import cv from google.colab.patches import cv2_imshow import numpy as np uploaded = files.upload()

Read and process image

for filename in uploaded.keys():

Read color image

img = cv2.imread(filename)

Smoothing using Gaussian Blur

smooth = cv2.GaussianBlur(img, (7,7), 0)

Sharpening using kernel filter

kernel = np.array([[0,-1,0], [-1,5,-1], [0,-1,0]]) sharpen = cv2.filter2D(img, - 1, kernel)

Show images

print("Original Image") cv2_imshow(img)