0% found this document useful (0 votes)
57 views4 pages

Plueseval - Numpy - Image

Pluesval

Uploaded by

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

Plueseval - Numpy - Image

Pluesval

Uploaded by

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

2.

Plueseval - Numpy - Image


Processing

Numpy: Image Processing

In this handson, you will


perform image processing and image
augmentation operations on the given-below
files.

Dataset Information:
Using numpy perform image processing and
image augmentation operations on animal.png.
The data sample for the required analysis is
available in the folder data.

There are 8 methods to be implemented in the


file main/solve.py:

· add_padding(self, img_data, pad_size):


o Add black padding around an image based
on the given pad_size parameter.

o return the numpy array with black


padding around an image

. crop_it(self, img_data, top, bottom,


left, right):
o Crop an image based on given four-
parameter (top, bottom, left, right) using
Numpy Array Slicing

o return the numpy array of a cropped


image

. flip_left_to_right(self, img_data):
o Flip an image from left -> right, (flipping over
y_axis).

o return the numpy array of a flipped


image

. flip_top_to_bottom(self, img_data):
o Flip an image from top -> bottom, (flipping
over x_axis)

o return the numpy array of a flipped


image.

· rotate_180(self, img_data):
o Rotate an image by 180 degrees in a
clockwise direction.

o return the numpy array of a rotated


image

· mask_image(self, img_data,
mask_img_data):
o Composite the image according to the given
mask image. In the mask image, there will
white portion, have to composite the original
image in that white portion.

o return the numpy array of a masked


image

· clrreduction_image(self, img_data):
o Reduce the color intensity by 64 for a given
image.

o To reduce the color intensity, Making Pixel


values discrete by first division by 64 and
then multiply by the 64

o return the numpy array of a color


reduced image

· add_noise(self, img_data, noise_data):


o Add noise to the given numpy image using
the noise data parameter

o Adding noise is one of the processes in


image augmentation. By adding random
noise you can create more numbers of
images from a single image.

o To add noise, first, multiply by


noise_data and then added by the img_data

o return the numpy array of a noisy


image

______________________________________________________________________________

import numpy as np
import re

class Solution:
def add_padding(self, img_data, pad_size):
"""
Add black padding around an image based on given pad_size parameter.
:param img_data: numpy array of an image
:param pad_size: padding size
:return: numpy array with black padding around an image
"""
padded_img_data = np.pad(img_data, ((pad_size, pad_size), (pad_size,
pad_size), (0, 0)), mode='constant')
return padded_img_data

def crop_it(self, img_data, top, bottom, left, right):


"""
Crop an image based on given four parameter (top, bottom, left, right)
using Numpy Array Slicing
:param img_data: numpy array of an image
:param top: starting pixel on a top
:param bottom: ending pixel on a bottom
:param left: starting pixel on a left
:param right: ending pixel on a right
:return: numpy array of a cropped image
"""
cropped_img = img_data[top:bottom, left:right]
return cropped_img

def flip_left_to_right(self, img_data):


"""
Flip an image from left -> right, (flipping over y_axis)
:param img_data: numpy array of an image
:return: numpy array of a flipped image
"""
flipped_img = np.fliplr(img_data)
return flipped_img

def flip_top_to_bottom(self, img_data):


"""
Flip an image from top -> bottom, (flipping over x_axis)
:param img_data: numpy array of an image
:return: numpy array of a flipped image
"""
flipped_img = np.flipud(img_data)
return flipped_img

def rotate_180(self, img_data):


"""
Rotate an image by 180 degrees in a clockwise direction.
:param img_data: numpy array of an image
:return: numpy array of a rotated image
"""
rotated_img = np.rot90(img_data, k=2)
return rotated_img

def mask_image(self, img_data, mask_img_data):


"""
Composite the image according to the given mask image. In mask image there
will white portion, have to composite the original image in that white portion.
:param img_data: numpy array of an image
:param mask_img_data: numpy array of an mask image
:return: numpy array of a masked image
"""
masked_img = np.where(mask_img_data == 255, img_data, 0)
return masked_img

def clrreduction_image(self, img_data):


"""
Reduce the color intensity by 64 for given image.
To reduce the color intensity, Making Pixel values discrete by first
division by 64 and then multiply by the 64
:param img_data: numpy array of an image
:return: numpy array of a color reduced image
"""
reduced_img = (img_data // 64) * 64
return reduced_img

def add_noise(self, img_data, noise_data):


"""
Add noise to the given numpy image using noise data parameter.
Adding noise is one of the process in image augmentation. By adding random
noise you can create more number images from a single image.
:param img_data: numpy array of an image
:param noise_data: numpy array of a noise
:return: numpy array of a noisy image
"""
noisy_img = img_data + noise_data
return noisy_img

You might also like