Because of the article the other day, I became a little interested in image processing. However, the last time I touched mathematics was the final exam of high school 3. Moreover, 2 points. There were some things that I couldn't understand, but first I wrote the code to try it out.
opencv2 seems to be a module for image processing. So it seems that I can't find it even if I do "pip install open cv2" easily. Apparently this is the correct one.
$ pip install opencv-python
The blurred image uses a country-like image of free material as an eye candy.
Let's blur this guy.
Let's write the code.
main.py
import cv2
#Load image
image = cv2.imread("inaka.jpg ")
This opencv2 seems to express the image in BGR. And matplotlib, a library that can be used to save and draw processed images, is in RGB format. If you use matplotlib, ignore the differences here and proceed! Lol
So, when converting from BGR to RGB, do this. This time, the processed image is not passed to matplotlib, so it is unnecessary.
main.py
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
It's finally time to start blurring. That said, just call the method.
main.py
blurr_image = cv2.GaussianBlur(image, (5, 5), 0)
This Guassian Blur, I didn't quite understand the argument. The first argument is an image object, the second argument is a numeric array called a kernel, and the third argument seems to be the standard deviation. It all sounds cosmic to me. I should have studied properly.
Now export the completed image.
main.py
cv2.imwrite("new_image.jpg ", blurr_image)
The whole code looks like this.
main.py
import cv2
image = cv2.imread("inaka.jpg ")
blurr_image = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imwrite("new_image.jpg ", blurr_image)
It's changed ...?
I tried playing with Gaussian Blur's arguments a little bit, but I couldn't grasp the rules and gave up today because I didn't have much time.
As an aside, I hate glasses because my eyes are too bad, and I'm afraid of contact lenses, so I can't put them in. Everything looks blurry from usual. I don't know at all whether it really blurred me. Perhaps the above image is also blurred, but I couldn't feel it, so I thought I'd turn it about 100 times repeatedly (I think it's definitely wrong).
main.py
import cv2
image = cv2.imread("inaka.jpg ")
for i in range(1,100):
image = cv2.GaussianBlur(image, (5, 5), 0)
cv2.imwrite("new_image.jpg ", image)
I feel like it's blurred properly.
By the way, even if I increased the number of repetitions any more, the degree of blur did not increase dramatically. I feel like there was someone who was familiar with the juniors who left the company, so I'd like to ask.
・ Image blur can be realized with opencv2 ・ I don't know how to use Guassian Blur, but it looks like it after repeating the muddy blurring process.
Recommended Posts