First, we can make two lists of x and y, where the values will be more than 1000. Then, we can use the ax.yaxis.set_major_formatter method where can pass StrMethodFormatter('{x:, }') method with {x:, } formatter that helps to separate out the 1000 figures from the given set of numbers.StepsMake two lists having numbers greater than 2000.Create fig and ax variables using subplots method, where default nrows and ncols are 1, using subplot() method.Plot line using x and y (from step 1).Set the formatter of the major ticker, using ax.yaxis.set_major_formatter() method, where StrMethodFormatter helps to make 1000 with common, i.e., expression ... Read More
In this program, we will read or load an image using the pillow library. The pillow library consists of a method called Image.open(). This function takes the file path or the name of the file as a string. To display the image, we use another function show(). It does not require any parameter.Example Codefrom PIL import Image im = Image.open('testimage.jpg') im.show()Output
In this program, we will crop an image using the Pillow library. We will use the crop() function for the same. The function takes left, top, right, bottom pixel coordinates to crop the image.Original ImageAlgorithmStep 1: Import Image from Pillow. Step 2: Read the image. Step 3: Crop the image using the crop function. Step 4: Display the output.Example Codefrom PIL import Image im = Image.open('testimage.jpg') width, height = im.size left = 5 top = height / 2 right = 164 bottom = 3 * height / 2 im1 = im.crop((left, top, right, bottom)) im1.show()Output
In this program, we will rotate an image using the pillow library. The rotate() function in the Image class takes in angle of rotation.Original ImageAlgorithmStep1: Import Image class from Pillow. Step 2: Open the image. Step 3: Rotate the image. Step 4: Display the output.Example Codefrom PIL import Image im = Image.open('testimage.jpg') im.rotate(45).show()Output
In this program, we will perform binary thresholding on an image using openCV.Thresholding is a process in which the value of each pixel is changed in relation to a threshold value. The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In binary thresholding, if the value of the pixel is less than the threshold, it will be given a 0 value, i.e., black. If it is greater than the threshold, it will be assigned 255, i.e., white.Original ImageAlgorithmStep 1: Import cv2. Step 2: Define ... Read More
Just using the savefig method of the pyplot package and mentioning the file format, we can save the output as a SVG format.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Create xpoints and ypoints using np.array(0, 5).Plot lines using xpoints and ypoints.Set the X-axis label using plt.xlabel() method.Set the Y-axis label using plt.ylabel() method.To save the file in SVG format, use savefig() method where image name is myImagePDF.svg, format="svg".To show the image, use plt.show() method.Exampleimport matplotlib.pyplot as plt import numpy as np fig, ax = plt.subplots() xpoints = np.array([0, 5]) ypoints = np.array([0, ... Read More
In this program, we will perform inverse binary thresholding on an image using openCV. Thresholding is a process in which the value of each pixel is changed in relation to a threshold value.The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In inverse binary thresholding, if the value of the pixel is less than the threshold, it will be given a maximum value i.e. white. If it is greater than the threshold, it will be assigned 0, i.e., black.Original ImageAlgorithmStep 1: Import cv2. Step ... Read More
Using the figsize attribute of figure(), we can change the figure size. To change the format of a figure, we can use the savefig method.StepsStore the figure size in the variable.Create a new figure, or activate an existing figure, with given figure size.Plot the line using x.Set the image title with its size.Save the figure using savefig() method.Examplefrom matplotlib import pyplot as plt figure_size = (10, 10) plt.figure(figsize=figure_size) x = [1, 2, 3] plt.plot(x, x) plt.title("Figure dimension is: {}".format(figure_size)) plt.savefig("imgae.png", format="png")Output
In this program, we will perform truncate thresholding on an image using openCV. Thresholding is a process in which the value of each pixel is changed in relation to a threshold value.The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In truncate thresholding, values greater than the threshold are reduced to the threshold value. Every other pixel remains the same.Original ImageAlgorithmStep 1: Import cv2. Step 2: Define threshold and max_val. Step 3: Pass these parameters in the cv2.threshold value and specify the type of ... Read More
In this program, we will perform zero thresholding on an image using openCV. Thresholding is a process in which the value of each pixel is changed in relation to a threshold value. The pixel is given a certain value if it is less than the threshold and some other value if it is greater than the threshold. In zero thresholding, pixels having intensity value less than the threshold value are set to 0.Original ImageAlgorithmStep 1: Import cv2. Step 2: Define the threshold and max_val. Step 3: Pass these parameters in the cv2.threshold value and specify the type of thresholding you ... Read More