Matlab Yardım-Fotoğraf Yumuşatma
-
Matlabda fotoğrafı parametrik olarak yumuşatmayı bilen müritler varsa bir el atsa.Döngüler aracılığıyla yapılacak, filtre kullanılmayacak.Şimdiden teşekkürler
-
Ortalama filtreyi döngü aracılığıyla yapabilirsin. Görüntünün matrisinden 3x3 bölüm al, ortadaki pikseli diğer sekiz pikselin ortalamasına eşitle.
-
C++ fonksiyonu çevirip kullanabilirsin
- void segImage::imageNoiseRedM(){// Median Average Filter.
- int area[9];
- for(int i=1;i<height-1;i++){
- for(int j=1;j<width-1;j++){
- for(int k=-1;k<2;k++){
- for(int l=-1;l<2;l++){
- area[(k+1)*3+l+1]= data[(i+k)*step+j+l];// All neighbors of current pixel assign to the
- }// temporary area array
- }
- sort(area,area+9);// All neighbors of current pixel sorting.
- newData[i*step+j] = area[4];// Median of the area array is assign to the pixel value.
- }
- }
- for(int i=1;i<height-1;i++){// Temp array values assigned to the image data array.
- for(int j=1;j<width-1;j++){
- data[i*step+j] = newData[i*step+j];
- }
- }
- }
-
Bonus: bu filtreyi de kullanabilirsin.
- void segImage::imageBlur(){// Blur operation to blure our image before thresholding.
- int kernel[3][3] ={{1,1,1},// Kernel of Blur.
- {1,1,1},
- {1,1,1}};
- int temp;
- for(int i=1;i<height-1;i++){// Image Data and Kernel is convoluting.
- for(int j=1;j<width-1;j++){
- temp=0;
- for(int k=-1;k<2;k++){
- for(int l=-1;l<2;l++){
- temp = temp + (data[(i+k)*step+j+l]*kernel[k+1][l+1])/9;
- }
- }
- if(temp>255)// If temp bigger then 255 or smaller then 0 we have to assign limit values to them.
- temp= 255;
- if(temp<0)
- temp = 0;
- newData[i*step+j] = temp;// The new pixel value according to convolution value is putting
- }// to the temporary image data array.
- }
- for(int i=1;i<height-1;i++){// Temp array values assigned to the image data array.
- for(int j=1;j<width-1;j++){
- data[i*step+j] = newData[i*step+j];
- }
- }
- }
-
Bonus 2:
- void segImage::imageNoiseRedG(int size, float j){// Gaussian Blur Filter.
- float kernel[size][size];
- for(int k=0; k<size;k++){// Creating Gaussian Kernel According to the formula.
- for(int l=0; l<size; l++){
- kernel[k][l] = (1/(2*M_PI*j*j)) * pow( M_E,-1* (k*k + l*l) / 2*j*j );
- }
- }
- int temp;
- for(int i=size/2;i<height-size/2;i++){// Image Data and Kernel is convoluting.
- for(int j=size/2;j<width-size/2;j++){
- temp=0;
- for(int k=(int)-size/2;k<(int)size/2+1;k++){
- for(int l=-size/2;l<size/2+1;l++){
- temp = temp + (data[(i+k)*step+j+l]*kernel[k+(int)(size/2)][l+(int)(size/2)]);
- }
- }
- if(temp>255)// If temp bigger then 255 or smaller then 0 we have to assign limit values to them.
- temp= 255;
- if(temp<0)
- temp = 0;
- newData[i*step+j] = temp;// The new pixel value according to convolution value is putting
- }// to the temporary image data array.
- }
- for(int i=size/2;i<height-size/2;i++){// Temp array values assigned to the image data array.
- for(int j=size/2;j<width-size/2;j++){
- data[i*step+j] = newData[i*step+j];
- }
- }
- }
-
muhammedonur bunu yazdı
Bonus: bu filtreyi de kullanabilirsin.
- void segImage::imageBlur(){// Blur operation to blure our image before thresholding.
- int kernel[3][3] ={{1,1,1},// Kernel of Blur.
- {1,1,1},
- {1,1,1}};
- int temp;
- for(int i=1;i<height-1;i++){// Image Data and Kernel is convoluting.
- for(int j=1;j<width-1;j++){
- temp=0;
- for(int k=-1;k<2;k++){
- for(int l=-1;l<2;l++){
- temp = temp + (data[(i+k)*step+j+l]*kernel[k+1][l+1])/9;
- }
- }
- if(temp>255)// If temp bigger then 255 or smaller then 0 we have to assign limit values to them.
- temp= 255;
- if(temp<0)
- temp = 0;
- newData[i*step+j] = temp;// The new pixel value according to convolution value is putting
- }// to the temporary image data array.
- }
- for(int i=1;i<height-1;i++){// Temp array values assigned to the image data array.
- for(int j=1;j<width-1;j++){
- data[i*step+j] = newData[i*step+j];
- }
- }
- }
Eyvallah hocam.
- temp = temp + (data[(i+k)*step+j+l]*kernel[k+1][l+1])/9;
- step i anlayamadım aydınlatabilirmisin :D
-
Average Filtresi
Resimdeki her piksel yerine komşuları ile beraber ortalaması alınarak yeniden hesaplanır. Resimdeki gri düzeyler arasında keskin geçişler azalır; daha yumuşak geçişler söz konusudur. Resim üzerindeki kenarlarda bulanıklaşmaya (blur) yol açarlar.
Seçilen resime yumuşatma filtrelerinden 3x3 ve 5x5 basit ortalama (averaging) filtresi uygulayarak resimlerin görüntülenmesi uygulaması..
a=imread('kitap.jpg');
b=rgb2gray(a);
b=im2double(b);
[w,h]=size(b);
for i=2:(w-1)
for j=2:(h-1)
fa=i-1;fb=i+1;fc=j-1;fd=j+1;
fk=b(fa,fc)+b(fa,j)+b(fa,fd)+b(i,fc)+b(i,j)+b(i,fd)+b(fa,fd)+b(fb,fc)+b(fb,j)+b(fb,fd);fm=fk*1/9;
cikis(i,j)=fm;
if i>2 & j>2 & i<(w-1) & j<(h-1)
fe=i-2;ff=i+2;fg=j-2;fh=j+2;
fk=b(fe,fg)+b(fa,fg)+b(fa,fh)+b(fb,fg)+b(fb,fh)+b(i,fg)+b(i,fh)+b(fe,fc)+b(fe,j)+b(fe,fd)+b(fe,fh)+b(ff,fg)+b(ff,fc)+b(ff,j)+b(ff,fd)+b(ff,fh)+b(fa,fc)+b(fa,j)+b(fa,fd)+b(i,fc)+b(i,j)+b(i,fd)+b(fa,fd)+b(fb,fc)+b(fb,j)+b(fb,fd);
fm=fk*1/25;
cikisa(i,j)=fm;
end
end
end
subplot(1,3,1),subimage(b);
subplot(1,3,2),subimage(cikis);
subplot(1,3,3),subimage(cikisa);
-
omrcyln bunu yazdımuhammedonur bunu yazdı
Bonus: bu filtreyi de kullanabilirsin.
- void segImage::imageBlur(){// Blur operation to blure our image before thresholding.
- int kernel[3][3] ={{1,1,1},// Kernel of Blur.
- {1,1,1},
- {1,1,1}};
- int temp;
- for(int i=1;i<height-1;i++){// Image Data and Kernel is convoluting.
- for(int j=1;j<width-1;j++){
- temp=0;
- for(int k=-1;k<2;k++){
- for(int l=-1;l<2;l++){
- temp = temp + (data[(i+k)*step+j+l]*kernel[k+1][l+1])/9;
- }
- }
- if(temp>255)// If temp bigger then 255 or smaller then 0 we have to assign limit values to them.
- temp= 255;
- if(temp<0)
- temp = 0;
- newData[i*step+j] = temp;// The new pixel value according to convolution value is putting
- }// to the temporary image data array.
- }
- for(int i=1;i<height-1;i++){// Temp array values assigned to the image data array.
- for(int j=1;j<width-1;j++){
- data[i*step+j] = newData[i*step+j];
- }
- }
- }
Eyvallah hocam.
- temp = temp + (data[(i+k)*step+j+l]*kernel[k+1][l+1])/9;
- step i anlayamadım aydınlatabilirmisin :D
bu kodu opencv için yazmıştım. opencv de de bir resmin datasına dizi gibi erişemiyorsun.
elinde 3x5 lik bir dizi olsun. dizinin 2.satır 3.sütun elemanına erişmek istiyorsan: A[1][2] 2 boyutlu bir dizi için istediğin sonucu verir ancak tek boyutlu diziyi iki boyutlu gibi kullanmak istiyorsan A[1*genislik+2] yani step genişlik oluyor fakat opencv de genişlikle de aynı şey anlamına gelmiyor orası biraz opencv nin iç yapısıyla ilgili. step i kullanacaksın yani. matlab de de opencv var ancak onu mu kullanıyorsun bilmiyorum. son olarak bu yazdığım class ın constructor ını paylaşmamışım onu da atarsam daha rahat anlarsın herhalde.
segImage::segImage(IplImage *image) {// Constructor of segImage all necessary variables and methods are there.
img = image;// Getting image.
height =img->height;// height, width, step and data is assign to the related varaibles
width = img->width;
step = img->widthStep;
data = (uchar *)img->imageData;
newData = new uchar[width*height];// newdata will be used to store temp image data.
label = new int[width*height];// label array store the label of every pixels.
labelCount=1;// label count store how many label we have.
for(int i=0;i<width*height;i++)// the first value of every pixel label must be zero.
label[i]=0;// we will assign a label according to pixels positions.
}
-
oo matlab yapmışım :D
-
@
muhammedonur , @ r10aldinho çok teşekkür ediyorum yardımlarınızdan dolayı yaptım.Eyvallah @ CnkGn zamanı gelmişti :D