3 Ekim 2017 Salı

OpenCV Image Smoothing

Giriş
OpenCV image smoothing (blurring) için 4 tane yöntem sunuyor. Bunlar Averaging, Gaussian Blurring, Median Blurring ve Bileteral Filtering metodları. Bir resmin blurry olduğu şöyle anlaşılabilir.
Compute the fft and analyse the result. The Fourier transform tells you which frequencies are present in the image. If there is a low amount of high frequencies, then the image is blurry.
Resmin blur işleminden geçmesi yani bulanıklaştırılması normalde lossy yani kayıplı bir işlem. Bulanıklaştırma resmin bir kısmını gizlemek (örneğin insan yüzü) veya detayları azaltmak için (yumuşatma) için kullanılır. Bazı yazılımlar bir şekilde bulanıklaştırma işlemini geri alabiliyorlar.

Convolution
Açıklaması şöyle
The process for (trying) to deblur a blurry image is called convolution. This is not the same or the reverse of focusing on a sharp scene to produce a sharp image. They work differently.
Kernel
Image matristen daha küçük bir matristir. Bazen image filter olarak ta isimlendirilir. Genellikle işlem şöyledir
- kernel  image matris üzerinde bir alana yerleştirilir.
- kernel ve üzerine yerleştiği image matris elemanları çarpılır ve tüm çarpımların toplamı alınır. Bu toplam da image matris'te kernel'in tam ortasındaki konuma atanır.

1. GaussianBlur metodu
Gaussian Blur aynı zamanda Gaussian Smoothing olarak ta bilinir. Gaussian Blur her türlü resime uygun olmayabilir. Açıklaması şöyle
The Gaussian kernel corresponds to very smooth functions, and when that kernel is chosen the assumption is being made that smooth functions will provide a decent model. That's not always the case, and there are tons of other kernels that encode different assumptions about what you want your function class to look like. There are kernels for modeling periodic functions, non-stationary kernels, and a whole host of other things. For example, the smoothness assumption encoded by the Gaussian kernel is not appropriate for text classification...

Gaussian Noise Nedir
Rastgele dağılmış gürültüyü ifade eder. Gürültüyü gidermek için smoothing yapılabilir. Salt & Pepper koyu alanlarda beyaz, beyaz alanlarda koyu noktaları ifade eder.

Metod 6 tane parametre alır.
src image
kaynak resim
out image
sonuç resim
kernel
tek sayı kare matris. Size matrisinin 33x33 gibi büyük bir değer ile kullanılmaması daha iyi sonuç verebilir.
sigma x
double tipinde. Resmin ne kadar blur edileceğini belirtir. Ne olduğunu anlamadım
sigma y
double tipinde. Ne olduğunu anlamadım
border type
int tipinde. Ne olduğunu anlamadım 

Örnek
Çıktıyı aynı resime yazmak için şöyle yaparız.
Mat mat = ...;
GaussianBlur(mat, mat, Size(7,7), 1.5, 1.5);
Örnek
Çıktıyı farklı resime yazmak Şöyle yaparız.
 cv::GaussianBlur(crop,// input image
        imgBlurred,    // output image
        cv::Size(5, 5),// smoothing window width and height in pixels
        5);        // sigma value, determines how much the image will be blurred
Python ile şöyle yaparız.
# Blurring to get rid of some noise
self.img = cv2.GaussianBlur(self.img, (9, 9), 0)
2. medianBlur metodu
Açıklaması şöyle
Median filtering is common in reduction of certain types of noise in image processing. Especially salt and pepper noise. It works by picking out the median value in each color channel in each local neighbourhood of the image and replacing it with it. How large these neighbourhoods are can vary. Popular filter sizes (neighbourhoods) are for example 3x3 and 5x5 pixels
Şöyle yaparız. Genelde 3x3 veya 5x5 kernel kullanılır.
Mat image = ...

// blur will enhance edge detection
Mat blurred(image);
cv::medianBlur(image, blurred, 9);


Hiç yorum yok:

Yorum Gönder