Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
42 views

Assignment-4 NumPy Applications

This document provides an assignment on using NumPy and its applications. It introduces NumPy as a Python library for working with multidimensional arrays and linear algebra. The tasks involve loading CSV files as NumPy arrays, sorting arrays, reading and manipulating image data with OpenCV, performing arithmetic on arrays, converting images to grayscale, plotting histograms, filtering images, and comparing computation times with and without NumPy. Students are asked to complete 12 programming tasks that demonstrate common NumPy operations on arrays and images.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Assignment-4 NumPy Applications

This document provides an assignment on using NumPy and its applications. It introduces NumPy as a Python library for working with multidimensional arrays and linear algebra. The tasks involve loading CSV files as NumPy arrays, sorting arrays, reading and manipulating image data with OpenCV, performing arithmetic on arrays, converting images to grayscale, plotting histograms, filtering images, and comparing computation times with and without NumPy. Students are asked to complete 12 programming tasks that demonstrate common NumPy operations on arrays and images.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Software Engineering Lab

Spring 2024

Assignment-4: NumPy and its Applications

Learning objectives:
NumPy stands for Numerical Python. NumPy is a Python library used for working with arrays. It also
has functions for working in domain of linear algebra, fourier transform, and matrices. NumPy is a
general-purpose array-processing package. It provides a high-performance multidimensional array
object and tools for working with these arrays. It is the fundamental package for scientific computing
with Python.

Install Dependencies:
Before its application, ensure the following:

Numpy
pip install numpy
import numpy as np

OpenCV
pip install opencv-python
import cv2
img = cv2.imread(‘image.png’,cv2.IMREAD_COLOR )
cv2.imshow(‘OUTPUT’, img)

Matplot Library
pip install matplotlib
import matplotlib.pyplot as plt

Check time for execution


import time
seconds = time.time()

Once you install the requisite package, do the following tasks.

1. Write a program to load a .csv file as a NumPy 1-D array. Find the maximum and minimum
elements in the array.
Hint: For the data, use the .csv file “Book1.csv”

2. For the Numpy 1-D array as obtained in Q.1, sort the elements in ascending order.

3. For the sorted Numpy 1-D array as obtained in Q.2, reverse the array and print.

4. Write a program to load three .csv files (Book1.csv, Book2.csv, and Book3.csv)
as a list of Numpy 1-D arrays. Print the means of all arrays as a list.

5. Write a program to read an image, store the image in NumPy 2-D array. For the image
consider a.PNG. Display the image. Let the array be X.
Hint: Use OpenCV to work with image.
6. Copy the data in X to another NumPy 2-D Array, say Y. Write a program to multiply two
NumPy 2-D arrays, that is, Z = X×Y.

7. For all the problems 6, repeat without using NumPy and compare the computation times
doing the same with NumPy.

8. Write a program to convert a color image (say a.PNG) and display its grayscale version.

9. Plot the pixel intensity histogram using the grayscale image.


Hint: Use matplotlib to plot

10. Create a black rectangle at the position [(40,100) top right, (70, 200) bottom left] in the
grayscale image.

11. For the grayscale image, display the binarized image with thresholds: [50, 70, 100, 150].
Hint: Binarizing is thresholding each pixel value, i.e., if pixel>threshold, then 1 else 0.

12. Consider the color image stored in a.png. Create a filter of [[-1,-1,-1][0,0,0][1,1,1]], and
multiply this filter to the image and output the resultant image.

Links to the data for this assignment:

Book1.csv Book2.csv Book3.csv a.png

For Q. 1-4: 5 Marks each.


For Q. 5-12, 10 marks each.

---*---

You might also like