0% found this document useful (0 votes)
4 views7 pages

Experiment 4

The document is a case study on advanced Numpy applications in image processing and compression, focusing on techniques like Singular Value Decomposition (SVD). It covers definitions of image processing and compression, their impact on quality, and practical coding examples for image reconstruction. Additionally, it discusses future career options in the field and concludes with insights gained from the study.

Uploaded by

Disha Deshmukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Experiment 4

The document is a case study on advanced Numpy applications in image processing and compression, focusing on techniques like Singular Value Decomposition (SVD). It covers definitions of image processing and compression, their impact on quality, and practical coding examples for image reconstruction. Additionally, it discusses future career options in the field and concludes with insights gained from the study.

Uploaded by

Disha Deshmukh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

BHARATIYA VIDYA BHAVAN’S

SARDAR PATEL INSTITUTE OF TECHNOLOGY


Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

Name Disha Hemant Deshmukh

UID no. 2023300044

Experiment No. 4

AIM: Advanced Numpy case study.

Question 1

QUESTION: Define Image Processing and Image Compression.

ANSWER: Image Processing :


Image processing refers to the use of computer algorithms to manipulate
digital images. The goal is to improve the image or extract important
information from it. For example, in medical imaging, image processing
techniques can help enhance the clarity of scans like X-rays or MRIs,
making it easier for doctors to analyze. Another common use is in
photography, where filters and adjustments like contrast and brightness are
applied to enhance the overall quality of the image. Image processing can
also be used for more advanced tasks like detecting and recognizing objects
in an image, which is essential for technologies like facial recognition or
self-driving cars.

Image Compression :
image compression is about reducing the size of image files so they take up
less storage space or can be transmitted more quickly over the internet.
There are two main ways to compress an image. In lossless compression, no
image data is lost during the process, so you can perfectly recover the
original image after decompression. This is useful when image quality must
be preserved, such as in scientific imaging. Lossy compression, however,
sacrifices some image quality to significantly reduce the file size. This
method is used when a smaller file is more important than perfect quality,
like when uploading photos to a website. JPEG is an example of lossy
compression, where some image details are discarded to reduce file size
while maintaining an acceptable level of visual quality.
Question 2
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

QUESTION: How does image compression affect the quality?


ANSWER: Image compression affects quality depending on the method used. In
lossless compression, the image quality remains unchanged because no data
is lost. The file size is reduced by efficiently encoding the image, but all the
original details are preserved. On the other hand, with lossy compression,
some of the image's details are permanently removed to make the file
smaller. This can result in a decrease in quality, like blurring or less
sharpness, especially when the compression is applied heavily. The more the
image is compressed, the more noticeable the quality loss becomes.

Question 3

QUESTION: What is the Single Value decomposition related to image matrix?

ANSWER: Single Value Decomposition (SVD) is a mathematical method used to break


down an image matrix into three smaller matrices. When you represent an
image as a matrix, with each element corresponding to pixel values, SVD
allows you to decompose this matrix into a product of three matrices: U, Σ,
V^T.
 U and V^T are orthogonal matrices that represent the patterns in the
rows and columns of the image.
 Σ is a diagonal matrix with singular values that describe the
importance of each pattern.
In image compression, SVD helps reduce the image size by keeping only
the most important singular values from Σ and discarding the rest. This way,
the image can be reconstructed using fewer values while still maintaining its
overall structure. However, the more singular values you discard, the more
details of the image you lose.
Question 4

QUSETION: What is use of singular value decomposition for machine learning?

ANSWER: Singular Value Decomposition (SVD) is useful in machine learning


for reducing the size of data while keeping important information.
By breaking data into simpler parts, SVD can help with tasks like:

1. Dimensionality reduction: SVD helps reduce the number of


features (variables) in a dataset, which can make models faster and
simpler without losing much accuracy.

2. Data compression: It compresses data by keeping only the most


important components, making it easier to store and process.
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

3. Noise reduction: SVD can filter out less important or noisy


information, improving the quality of the data for models.

Question 5

QUESTION: Observe the output of code in Jupyter notebook (colab) and explain the
code line by line.

ANSWER: First line imports the necessary libraries. numpy is used for numerical
operations and matplotlib.pyplot is used for plotting images.

np.random.seed(0) ensures that the random numbers generated are


reproducible.

np.random.rand(100, 100) generates a 100x100 array of random values


between 0 and 1. This simulates a grayscale image.

np.linalg.svd(image, full_matrices=False) computes the Singular Value


Decomposition (SVD) of the image matrix. SVD decomposes the image
matrix into three matrices: U, S, and Vt. Here, full_matrices=False ensures
that the returned matrices are of the appropriate reduced size.

k = 20 specifies the number of singular values to keep.

np.diag(S[:k]) creates a diagonal matrix S_k from the first k singular values.

U[:, :k] and Vt[:k, :] reduce the U and Vt matrices to the first k columns/rows.

np.dot(U_k, np.dot(S_k, Vt_k)) reconstructs the image using the reduced rank
matrices. This approximates the original image using only the top k singular
values.

plt.figure(figsize=(10, 5)) creates a figure with a specific size for better


visualization.

plt.subplot(1, 2, 1) sets up the first subplot. plt.title('Original Image') gives the


subplot a title. plt.imshow(image, cmap='gray') displays the original image in
grayscale. plt.axis('off') hides the axis labels and ticks.

plt.subplot(1, 2, 2) sets up the second subplot. plt.title('Compressed Image')


gives the subplot a title. plt.imshow(compressed_image, cmap='gray') displays
the compressed image in grayscale. plt.axis('off') hides the axis labels and
ticks.

plt.show() renders the plots


BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

Question 6

QUESTION: Write three future scope/career options in Image Processing field.

ANSWER: Medical Imaging Specialist:


This role focuses on enhancing the quality and accuracy of images produced
by medical technologies such as MRI, CT scans, and X-rays. As
advancements in AI and machine learning continue, specialists are needed to
develop sophisticated algorithms that can improve diagnostic accuracy and
automate the interpretation of medical images, thus playing a crucial role in
modern healthcare.

Autonomous Vehicle Vision Engineering:


Autonomous vehicles depend on sophisticated image processing systems to
navigate safely and effectively. As an engineer in this area, you'll work on
developing and refining computer vision algorithms that enable vehicles to
understand and react to their environment. With the automotive industry's
shift towards self-driving technology, this field offers dynamic and cutting-
edge career prospects.

Augmented Reality (AR) and Virtual Reality (VR) sector:


The Augmented Reality (AR) and Virtual Reality (VR) sector presents a
fascinating career avenue. In AR and VR, image processing is vital for creating
immersive and interactive experiences. Professionals in this field work on
enhancing visual elements, tracking real-world movements, and ensuring
seamless integration between the virtual and physical worlds. As AR and VR
technologies become more prevalent in entertainment, education, and beyond,
there will be increasing demand for expertise in image processing to push the
boundaries of what these technologies can achieve.

Question 7

QUESTION: Did you find the case study useful? Should we take such application-
oriented case study for further important Data science topics.
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

ANSWER: Yes, the case study on image compression using Singular Value Decomposition
(SVD) is useful. It demonstrates practical applications of advanced Numpy
operations and helps in understanding how dimensionality reduction techniques
can be applied to real-world data, like images.
Such application-oriented case studies are beneficial for grasping important data
science topics, as they show how theoretical concepts are implemented in
practice and how they can solve real problems.
Program

PROBLEM You need to perform image compression using Singular Value Decomposition
STATEME (SVD). The goal is to reduce the dimensionality of the image data while
NT: preserving as much of the original image as possible.
1. Create a Synthetic Image: Define a 2D numpy array with shape
(100, 100) to simulate an image.
2. Perform SVD (singular value decomposition): Compute the SVD of
the image matrix.
3. Reconstruct the Image with Reduced Rank: Reconstruct the image
using a limited number of singular values.
4. Plot the Original and Compressed Images: Compare the original and
compressed images.
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

PROGRAM: import numpy as np


import matplotlib.pyplot as plt

# 1. Create a Synthetic Image


np.random.seed(0)
image = np.random.rand(100, 100)

# 2. Perform SVD
U, S, Vt = np.linalg.svd(image, full_matrices=False)

# 3. Reconstruct the Image with Reduced Rank (e.g., using 20 singular


values)
k = 20
S_k = np.diag(S[:k])
U_k = U[:, :k]
Vt_k = Vt[:k, :]
compressed_image = np.dot(U_k, np.dot(S_k, Vt_k))

# 4. Plot the Original and Compressed Images


plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.title('Original Image')
plt.imshow(image, cmap='gray')
plt.axis('off')

plt.subplot(1, 2, 2)
plt.title('Compressed Image')
plt.imshow(compressed_image, cmap='gray')
plt.axis('off')

plt.show()

RESULT: In this problem, we use Singular Value Decomposition (SVD) to compress


an image by reducing its dimensionality. The main objective is to
reconstruct the image using a limited number of singular values, which
helps preserve the essential characteristics of the image while discarding
less critical information. This method enables efficient storage and
transmission by focusing on the most significant elements of the image,
leading to a smaller file size with minimal impact on visual quality.
BHARATIYA VIDYA BHAVAN’S
SARDAR PATEL INSTITUTE OF TECHNOLOGY
Bhavan’s Campus, Munshi Nagar, Andheri (West), Mumbai – 400058-India
Department of Computer Engineering

OUTPUT:

CONCLUSION: From this problem, I learned that by utilizing only a limited number of the
most significant singular values, I can effectively compress an image. This
approach reduces the overall data required for storing the image while
retaining the crucial features. The exercise highlighted the balance between
compression and image quality. By using just the top 20 singular values, I
was able to produce a compressed image that, although less detailed, still
resembled the original.

The visual comparison of the original and compressed images


demonstrated how SVD-based compression manages to keep essential
visual elements intact even as data is reduced. This practical application of
SVD has also enhanced my understanding of matrix operations, including
how to manipulate and apply them to achieve specific objectives. Overall,
this case study was valuable for deepening my knowledge of image
processing techniques and their real-world applications.

You might also like