0% found this document useful (0 votes)
15 views6 pages

Lab Report 1

The document discusses 5 tasks completed in an image processing lab. Task 1 involves sorting a tuple by its second element. Task 2 finds the key of the minimum value in a dictionary. Task 3 converts a user-input integer between binary, octal, and hexadecimal. Task 4 performs min-max normalization on a list. Task 5 calculates the average temperature of non-overlapping 2x2 grids in a 6x6 matrix.

Uploaded by

Uzair Waheed
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)
15 views6 pages

Lab Report 1

The document discusses 5 tasks completed in an image processing lab. Task 1 involves sorting a tuple by its second element. Task 2 finds the key of the minimum value in a dictionary. Task 3 converts a user-input integer between binary, octal, and hexadecimal. Task 4 performs min-max normalization on a list. Task 5 calculates the average temperature of non-overlapping 2x2 grids in a 6x6 matrix.

Uploaded by

Uzair Waheed
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/ 6

DEPARTMENT OF COMPUTER & SOFTWARE

ENGINEERING

COLLEGE OF E&ME, NUST, RAWALPINDI

EC312 Digital Image Processing


Lab Report - 01

SUBMITTED TO:
LE Ma’am Sundas Ashraf

SUBMITTED BY:
Uzair Waheed
Reg # 371828
DE- 43 CE

Submission Date:18/02/24

1|Page
Lab-01: Introduction to Python & Python Package
Lab Tasks

Task-1:
Write a function Sort_tuple() that sort a tuple of tuples by its 2nd item and return
tuple.
Input: tuple1 = (('a', 23),('b', 37),('c', 11), ('d',29))
Output: (('c', 11), ('a', 23), ('d', 29), ('b', 37)).
Code:

import numpy as np
import matplotlib as plt
import cv2

tuple_1 = (('a', 23), ('b', 37), ('c', 11), ('d', 29))


print("Tuple: " , tuple_1)

def Sort_tuple(tuple_1):
tuple_1 = list(tuple_1)
for i in range(len(tuple_1)-1):
for j in range(len(tuple_1)-1):
if tuple_1[i][1] > tuple_1[j+1][1]:
temp = tuple_1[j]
tuple_1[j] = tuple_1[j+1]
tuple_1[j+1]= temp
return tuple(tuple_1)

print("Sorted Tuple: ",(Sort_tuple(tuple_1)))

Output:

2|Page
Task-2:
Write a function to get the key of a minimum value from the dictionary data holder:
Input: Dict = {'Physics': 82, 'Math': 65,'history': 75}
Output: Math
Code:

Dict = {'Physics': 82, 'Math': 65,'history': 75}


print("Dictionary: " ,Dict)
def get_min(Dict):
Dict = list(Dict.items())
for i in range(len(Dict) - 1):
for j in range(len(Dict) - 1):
if Dict[j][1] > Dict[j + 1][1]:
temp = Dict[j]
Dict[j] = Dict[j + 1]
Dict[j + 1] = temp

return Dict[0][0]

print("Key of Minimum value in Dictionary : ",get_min(Dict))

Output:

Task-3:
Write a program that takes an integer as an input from the user and represents it in
binary, octal or hexadecimal. The user should specify the output number system i.e.
whether the number should be converted to binary, octal or hexadecimal.

Code:

3|Page
def represent(num,rep):
rep=rep.upper()
if(rep=='B'):
return bin(num)
elif(rep == 'O'):
return oct(num)
elif(rep=='H'):
return hex(num)

num= input("Enter Number you want to convert : ")


rep= input("Enter base of Number system : ")
print("The number after conversion is ",represent(int(num),rep),rep)

Output:

Task-4:
Min-Max normalization is one of the normalization techniques that can be used for
numerical data. It is performed using the following operation: Write a function
min_max_normlaization that takes a list as input and performs the min-max
normalization on it. The length of the list can vary.
Code:

import numpy as np

def normalization(l):
min_val = min(l)
max_val = max(l)
newList = np.array(l)
return (newList - min_val) / (max_val-min_val)

list_1 = [312,41,55,11,5,142,56,1,9]
print("List : ",list_1)
print("After Normalization: \n", normalization(list_1))

4|Page
Output:

Task-5:
Write a Python function that takes a 2D array of size 6*6 representing temperature
readings should be in range of (1 to 50) across the region and returns the average
temperature for each non-overlapping 2x2 grid within the region.
Code:

import numpy as np

matrix = np.random.randint(0,51,(6,6),dtype=int)

print("6x6 Matrix : \n", matrix)


list_1=[]
for i in range(0,5,2):
for j in range(0,5,2):
print("\nfor : (",i,j,") index\n")
print(matrix[i][j]) ," ", print(matrix[i][j + 1]) ," ",
print(matrix[i + 1][j]) ," ", print(matrix[i + 1][j + 1])

list_1.append((matrix[i][j]+matrix[i][j+1]+matrix[i+1][j]+matrix[i+1][j+1])/4
)

print("\nAverage of 2x2 Matrix : ",list_1)

print("After Normalization: \n", normalization(list_1))

Output:

5|Page
6|Page

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy