0% found this document useful (0 votes)
33 views5 pages

Dip Asnam

This document contains code for digital image processing tasks. It includes code to [1] resize an image to 512x512 pixels and downsample it to 128x128, and [2] create an image with colored corners (red, green, blue, black) by calling a function that generates the image. The code accomplishes basic image processing operations like resizing, cropping and color manipulation.

Uploaded by

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

Dip Asnam

This document contains code for digital image processing tasks. It includes code to [1] resize an image to 512x512 pixels and downsample it to 128x128, and [2] create an image with colored corners (red, green, blue, black) by calling a function that generates the image. The code accomplishes basic image processing operations like resizing, cropping and color manipulation.

Uploaded by

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

Digital Image Processing

Ma’am Amna Waheed


Assigmnent 1

NAME::Irfan Haider
CLASS: BCE-7
ENROLLMENT NO: 01-132182-035

DEPARTMENT OF COMPUTER ENGINEERING


BAHRIA UNIVERSITY | ISLAMABAD CAMPUS
Code

import cv2

import numpy as np

img = cv2.imread('Irfan.jpg',0);

img512 = cv2.resize(img,(512,512));

cv2.imshow('orig',img);

cv2.imshow('512x512',img512);

img128 = img512[::4 , ::4];

cv2.imshow('128x128',img128);

cv2.imwrite('img128.jpg',img128);

cv2.waitKey(0);
Code

import numpy as np

import cv2

import math

def color(imgSize):

cornerSize = int(math.floor(imgSize/8));

img = np.ones((imgSize,imgSize,3));

#red

img[:cornerSize, :cornerSize] = (0,0,1);

#green

img[:cornerSize:, -cornerSize:] = (0,1,0);

#blue

img[-cornerSize:, :cornerSize] = (1,0,0);

#black

img[-cornerSize:, -cornerSize:] = (0,0,0);

cv2.imshow('Asnam',img);

cv2.waitKey(0);

return;

color(800);
Conclusion

In question 1 I have read the original image and the convert into 512x512 size and then convert to
128x128.

In question 2 I have created a function for white image and then I have created 4 boxes of Red green
blue and black the corner of image

You might also like