0% found this document useful (0 votes)
23 views

DIP Assignment 1

This document contains the details of a student named Karthikeyan Ravichandran completing tasks for a digital image processing lab. The student read an image file, displayed it, extracted pixel coordinate and intensity values, converted the image to grayscale, and answered questions about the differences between processing the original and grayscale images.

Uploaded by

karthikeyan R
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

DIP Assignment 1

This document contains the details of a student named Karthikeyan Ravichandran completing tasks for a digital image processing lab. The student read an image file, displayed it, extracted pixel coordinate and intensity values, converted the image to grayscale, and answered questions about the differences between processing the original and grayscale images.

Uploaded by

karthikeyan R
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME : KARTHIKEYAN RAVICHANDRAN

PSID : 2260006

EDS 6397 - DIGITAL IMAGE PROCESSING

LAB -1 READING AN IMAGE

TASK 1

Read and Display the Image


#importing the necessary libraries
import numpy as np
import cv2
import matplotlib
from matplotlib import pyplot as plt

# Reading the image using cv2.imread function


img = cv2.imread("DIP_Profile.jpeg", cv2.IMREAD_COLOR)

# Converting BGR to RGB ->(By default OpenCV uses BGR format of images)
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Displaying the image using matplotlib


plt.imshow(img_rgb)
plt.title("Output Image")
# Turn off axis labels
plt.axis('off')
plt.show()

Saving the image


cv2.imwrite(r"C:\Users\karth\OneDrive\Documents\GitHub\lab-assignment-1-Karthiknmsd37\output_images\DIP_output_1.png"

True

Printing the co-ordinates and picture intensity


%matplotlib notebook
import cv2
import matplotlib.pyplot as plt

# Function to handle mouse events


def on_pick(event):
if event.inaxes is not None:
x, y = int(event.xdata), int(event.ydata)
print(f"Clicked at coordinates (x={x}, y={y})")

# Check if the image was successfully loaded


if img is not None:
# Convert BGR to RGB
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Display the image using Matplotlib


fig, ax = plt.subplots()
ax.imshow(img_rgb)
ax.set_title("Hover on the image to get coordinates and intensity")

# Connect the pick event to the callback function


fig.canvas.mpl_connect("button_press_event", on_pick)

else:
print("Image not found or unable to read.")

#We can hover the cursor over the image to get readily the co-ordinates and intensity for that particular pixel.

Alternate way tried to just get the first 5 pixels without tracer
events
#reshaping the array
reshaped_img = img_rgb.reshape(-1, 3)

# Convert the reshaped array to a list


pixel_values = reshaped_img.tolist()
#printing the co-ordinates
height, width, _ = img_rgb.shape
print("x:",width)
print("y:",height)
# prints the first 5 rows of pixel values of the image
print(pixel_values[0:5])

x: 656
y: 825
[[90, 88, 91], [90, 88, 91], [90, 88, 91], [90, 88, 91], [90, 88, 89]]

Q} Is this a digital image? Explain why.


Ans :Yes.

Digital images are typically represented as arrays of numerical values, where each value represents the color or intensity of a pixel.
Digital images are composed of discrete elements called pixels, each with its own digital value representing color or intensity.
Here we are able to analyze and get each pixel's co-ordinates and their respective intensity value.

TASK 2
TASK 2

Converting the image to gray scale and printing the co-ordinates


and intensity values
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Display the grayscale image using Matplotlib


fig, ax = plt.subplots()
plt.title("Output Image")
ax.imshow(img_gray, cmap='gray') # Use 'gray' colormap for grayscale

#We can hover the cursor over the image to get readily the co-ordinates and intensity for that particular pixel.

<matplotlib.image.AxesImage at 0x1292960faf0>

#reshaping the array


reshaped_img = img_gray.reshape(-1, 1)

# Convert the reshaped array to a list


pixel_values = reshaped_img.tolist()
height, width, _ = img_rgb.shape

#printing the co=ordinates


print("x:",width)
print("y:",height)
# prints the first 5 rows of pixel values of the image
print(pixel_values[0:5])

x: 656
y: 825
[[89], [89], [89], [89], [89]]

Saving the image


cv2.imwrite(r"C:\Users\karth\OneDrive\Documents\GitHub\lab-assignment-1-Karthiknmsd37\output_images\DIP_output_2.png"

True

Q} Is this a digital image? Explain why.


Ans :Yes.

Digital images are typically represented as arrays of numerical values, where each value represents the color or intensity of a pixel.
Digital images are composed of discrete elements called pixels, each with its own digital value representing color or intensity.
Here we are able to analyze and get each pixel's co-ordinates and their respective intensity value.

Task 3
Task 3
Q}Is there any difference between the co-ordinates from 1 and 2? Explain.
Ans: No.

As we are just representing the same image but in a different format of colors, the position of the pixels is not varying.
Hence there is no difference between the co-ordinates from 1 and 2.

Task 4
Q}Is there any difference between the pixel values from 1 and 2? Explain.
Ans:Yes.

Since in an RGB image, each pixel contains three values representing the intensity of the red, green, and blue color channels
respectively, it is a mixture of all those planes and the values range from 0 to 255.
Though a grayscale image typically has pixel intensity values ranging from 0 to 255 but they contain only one value representing the
intensity of light at that point where 0 represents black and 255 represents white.

Loading [MathJax]/jax/output/CommonHTML/fonts/TeX/fontdata.js

You might also like