![]() ![]() TransMat = np.float32(,]) # translation matrixĭimensions = (img.shape, img.shape) # image width, height The values 0,1, -1 specify the flip code for flipping an image.īelow code shows all the transformations applied on image: import cv2 as cvĭef translate(img, x, y): # x,y specify the axis for translation We can flip an image vertically(0), horizontally(1), vertically and horizontally(-1). OpenCV allows you to specify any rotation point that you would like to rotate the image around. Using translation you can shift an image up(-y), down(y), left(-x), right(+x) or with any combinations. Translation is basically shifting of an image along the x and y axis. Below code displays the above operations performed on image : img = cv2.imread(r"dog_1.jpg", 1)īlur = cv2.GaussianBlur(img,(5,5),cv2.BORDER_DEFAULT)ĭilated = cv2.dilate(canny, (7,7), iterations = 4) # (7,7) - kernel size & iterations can be changedĬv2.imshow('Blurred image Edge cascade',canny)īasic image transformation techniques includes Image Translation, Rotation, Flipping, Cropping and Resizing of images. It helps join some broken parts of an object in image. With dilation we can get better noise removal results. Image Dilating increases the object area. It is applied on blurred images to gain the edges or features from image. Edge CascadingĬanny edge detection is a popular edge detection algorithm. Gaussian blur is the result of blurring an image by Gaussian function. They are Gaussian Blur, Median Blur and Bilateral Blur. It helps in removing noise in image and smoothing image. It is done with the help of various low pass filter kernels. Image Blurring refers to making the image less clear or distinct. These are preprocessing step for building Machine Learning and Deep Learning model. In this section, we will look at some of the functions that are usually applied on image data. Similarly can also draw a circle, eclipse, line and polylines. Image name (img), Text to add in image, Position where to add text & others are fontFace, fontScale, Color, Thickness and LineType for text. cv2.putText() function adds text in image. Image name(img), Vertex of angle (point1), Vertex of rectangle opposite to point1 (point2), Color of rectangle (0,0,255) represents red color.Ģ. The image drawn using np.zeros() by default draws a blank image.Ĭv2.rectangle() function takes the below parameters to draw a rectangle. Return cv2.resize(frame,dimensions,interpolation= cv2.INTER_AREA) # Resize ImageĬv2.imshow('Resized image', frame_resized) import cv2ĭef rescaleFrame(frame,scale = 0.75): # Rescale Image In below code the image size is rescaled to 75% of its total size. Usually we try to downscale the width and height of images. ![]() Here we are actually try to get rid of some of that information. Large media files tends to store a lot of information. We resize and rescale images and files to prevent computational strain. ![]() Print("Datatype of image : ",img.dtype) # returns image dtype obtained 3. Print("Sizeof Image : ",img.size) # returns total number of pixels is accessed Get details of image print("Shape of image : ",img.shape) # returns a tuple of number of rows,columns, and channels If you want to destroy any specific window, use the function cv2.destroyWindow() where you pass the exact window name as the argument. If 0 is passed, it waits indefinitely for a key stroke.Ĭv2.destroyAllWindows() simply destroys all the windows we created. If you press any key in that time, the program continues. The function waits for specified milliseconds for any keyboard event. Its argument is the time in milliseconds. Loads image as such including alpha channelĬv2.imshow() function has Name of image screen and image to display paramters.Ĭv2.waitKey() is a keyboard binding function. The imread() function reads the image in different forms : Image form ![]()
0 Comments
Leave a Reply. |