In this program, we will blur an image using the opencv function blur().AlgorithmStep 1: Import OpenCV. Step 2: Import the image. Step 3: Set the kernel size. Step 4: Call the blur() function and pass the image and kernel size as parameters. Step 5: Display the results.Original ImageExample Codeimport cv2 image = cv2.imread("testimage.jpg") kernel_size = (7,7) image = cv2.blur(image, kernel_size) cv2.imshow("blur", image)OutputBlurred ImageExplanationThe kernel size is used to blur only a small part of an image. The kernel moves across the entire image and blurs the pixels it covers.
In this program, we will write text on an image using the opencv function putText(). This function takes in the image, font, coordinates of where to put the text, color, thickness, etc.Original ImageAlgorithmStep 1: Import cv2 Step 2: Define the parameters for the puttext( ) function. Step 3: Pass the parameters in to the puttext() function. Step 4: Display the image.Example Codeimport cv2 image = cv2.imread("testimage.jpg") text = "TutorialsPoint" coordinates = (100,100) font = cv2.FONT_HERSHEY_SIMPLEX fontScale = 1 color = (255,0,255) thickness = 2 image = cv2.putText(image, text, coordinates, font, fontScale, color, thickness, cv2.LINE_AA) cv2.imshow("Text", image)Output
To test for the significance of proportion between two categorical columns of an R data frame, we first need to find the contingency table using those columns and then apply the chi square test for independence using chisq.test. For example, if we have a data frame called df that contains two categorical columns say C1 and C2 then the test for significant relationship can be done by using the command chisq.test(table(df$C1,df$C2))Example Live Demox1
We can use the twiny() method to create a second X-axis. Similarly, using twinx, we can create a shared Y-axis.StepsCreate fig and ax variables using subplots method, where default nrows and ncols are 1.Plot line with lists passed in the argument of plot() method with color="red".Create a twin of Axes with a shared Y-axis but independent X-axis.Plot the line on ax2 that is created in step 3.Adjust the padding between and around subplots.To show the figure, use plt.show() method.Exampleimport matplotlib.pyplot as plt fig, ax1 = plt.subplots() ax1.plot([1, 2, 3, 4, 5], [3, 5, 7, 1, 9], color='red') ax2 = ax1.twiny() ... Read More
The shape property is usually used to get the current shape of an array, but it may also be used to reshape the array in-place by assigning a tuple of array dimensions to it.StepsGet an array Y using np.array method.Y.shape would return a tuple (4, ).Y.shape[0] method would return 4, i.e., the first element of the tuple.Exampleimport numpy as np Y = np.array([1, 2, 3, 4]) print("Output of .show method would be: ", Y.shape, " for ", Y) print("Output of .show[0] method would be: ", Y.shape[0], " for ", Y) print("Output for i in range(Y.shape[0]): ", end=" ") for ... Read More
To replace a particular value in R data frame with a new value, we can use ifelse function where the new value will be placed after the condition and if the column values do not match the condition then the same column will be placed. For example, if we have a data frame called df that contains a column x having 20 values and some of them are 5 and if we want to replace 5 with 2 then we can use the command df$x
To create boxplot in base R with higher width of the box lines, we can use the boxlwd argument inside boxplot function. For example, if we have a vector called x then we can create the boxplot with higher width of the box lines using the command −boxplot(x,boxlwd=5)Example Live Demox
To find the fractional power of a negative number, we can find the power separately for the numerator and denominator where denominator will have the numerator 1. For example, if we have a vector called x that contains a single value -10 then the fractional power 15/7 of x can be found by using the command ((x)^15)^(1/7)Example Live Demox1
To find the sum of every n values in R data frame columns if there exist missing values, we can use rowsum function along with rep function that will repeat the sum for rows and na.rm=TRUE to exclude the rows with missing values. For example, if we have a data frame called df that contains 4 columns each containing twenty values with some missing values then we can find the row sums for every 5 rows by using the command rowsum(df,rep(1:5,each=4),na.rm=TRUE).Example Live Demox1
In this program, we will draw a simple line on an image using the OpenCV function line().Original ImageAlgorithmStep 1: Import cv2. Step 2: Read the image using imread(). Step 3: Get the dimensions of the image using the image.shape method. Step 4: Define starting point of the line. Step 5: Define the end point of the line. Step 6: Define the thickness of the line. Step 7: Draw the line using the cv2.line() function and pass Step 3 to Step 4 as parameters.Example Codeimport cv2 image = cv2.imread('testimage.jpg') height, width, channels = image.shape startpoint = (0, 0) endpoint = ... Read More