Mia Nanasawa's face is (No'□ `) No Noise processing is applied to return to the original beautiful face

Introduction

七沢みあノイズ

** Mia Nanasawa is cute, isn't she? ** **

"that?" "It's different than usual. It's strange ..."

If you zoom in ...

Is there something ** like sesame salt with black and white dots ** mixed in?

This doesn't allow you to focus on your cute face.

** Smooth ** and ** remove black and white dots **!

What is smoothing?

** Blur the image **. OpenCV provides four types of blurring methods (filters).

―― 1: Moving average filter (averaging filter)

-2: Gaussian filter

―― 3: Median filter

―― 4: Bilateral filter

データ

【Caution】 -"Brightness" is simply a desaturation of a color. -"Brightness" takes into account the difference in brightness depending on the color.

image.png ** ex) For blue (R: 0 G: 0 B: 255) ** image.png

1: Moving average filter (averaging filter)

データ データ
#blur means "blurring".
img = cv2.imread("nana.jpg ")#Load image file with openCV
img_blur = cv2.blur(img, (3, 3))#First argument=Image file,Second argument=Filter width,Vertical width
imgs = cv2.hconcat([img, img_blur])#Connect images of equal height horizontally

cv2.imwrite("nana1.jpg ",imgs)#Save image file with openCV
データ

☚ The left figure is the original image ☛ The right figure is the image with ** averaging filter **

The noise on the right is blurred. It seems difficult to erase it completely. ..

Averaging filter (filter size from 1x1 to 6x6)

img1 = cv2.blur(img, (1, 1))
img2 = cv2.blur(img, (2, 2))
img3 = cv2.blur(img, (3, 3))
img4 = cv2.blur(img, (4, 4))
img5 = cv2.blur(img, (5, 5))
img6 = cv2.blur(img, (6, 6))

imgs_1 = cv2.hconcat([img1, img2, img3])
imgs_2 = cv2.hconcat([img4, img5, img6])
imgs = cv2.vconcat([imgs_1, imgs_2])#Vertically concatenate images of equal width
cv2.imwrite("nana2.jpg ", imgs)

nana6.jpg

From the upper left, the image will have the filter size increased. You can see that the blurring of the image is ** stronger and stronger **. ** The photo on the bottom right is now able to concentrate on Mia-chan without worrying about white sesame seeds! !! ** **

2: Gaussian filter

Calculated weights in the filter according to ** Gaussian distribution **.

データデータ

** [Difference from averaging filter] ** The ** replacement value ** is to be replaced so that the pixel of interest in the center ** has the largest weight ** and the outer pixel has the smaller weight **. This characteristic makes it possible to blur the image ** while leaving more information around the pixels.

img_gauss = cv2.GaussianBlur(img, (3, 3), 3)#The third argument is the Gaussian function σ
imgs = cv2.hconcat([img, img_gauss])
cv2.imwrite("nana3.jpg ", imgs)
データ

☚ The left figure is the original image ☛ The right figure is the image with ** Gaussian filter (σ = 3) **

It's not much different from the ** 1 averaging filter **

3: Median filter

The ** median ** extracted from the pixels contained in the specified filter and replaced.

** [Difference from averaging filter] ** The ** replacement value ** is not the averaged pixel value, but the ** always existing ** pixel value is used.

img_med = cv2.medianBlur(img, 3)
imgs = cv2.hconcat([img, img_med])
cv2.imwrite("nana4.jpg ", imgs)
データ

☚ The left figure is the original image ☛ The right figure is the image with ** median filter **

** Wow ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ぉ ** ** Sesame salt is gone ** ** I'm the cutest Mia ever! !! ** **

4: Bilateral filter

** Other than edges ** are Gaussian filters. The Gaussian filter is performed by setting the weight to "0" in the portion where the brightness difference is large.

データ →  データ

** [Differences from conventional smoothing filters] ** ** Being able to blur the image while leaving the edges **

img_bi = cv2.bilateralFilter(img, 9, 75, 75)
imgs = cv2.hconcat([img, img_bi])
cv2.imwrite("nana5.jpg ", imgs)
データ

☚ The left figure is the original image ☛ The right figure is the image with ** bilateral filter **

result

Since the salt and pepper this time was a clear noise, it turned out that it was best to apply a ** median filter **.

I also felt that ** bilateral filter ** would be suitable if ** noise saturation ** is close to ** original data ** noise.

If you find noise in your favorite images, filter them!

Recommended Posts

Mia Nanasawa's face is (No'□ `) No Noise processing is applied to return to the original beautiful face
Return one-hot encoded features to the original category value
Use the pushd command, which is more convenient than the cd command, to instantly return to the original directory.
The story that CSS is no longer applied after uploading the Django app from local to AWS