File:Image restoration (motion blur, Wiener filtering).png
From Wikimedia Commons, the free media repository
Jump to navigation
Jump to search
![File:Image restoration (motion blur, Wiener filtering).png](https://upload.wikimedia.org/wikipedia/commons/thumb/e/e3/Image_restoration_%28motion_blur%2C_Wiener_filtering%29.png/800px-Image_restoration_%28motion_blur%2C_Wiener_filtering%29.png?20081213031419)
Size of this preview: 800 × 267 pixels. Other resolutions: 320 × 107 pixels | 640 × 213 pixels | 1,464 × 488 pixels.
Original file (1,464 × 488 pixels, file size: 982 KB, MIME type: image/png)
File information
Structured data
Captions
Captions
Add a one-line explanation of what this file represents
Summary
[edit]DescriptionImage restoration (motion blur, Wiener filtering).png |
English: Image restoration (motion blur, Wiener filter). Deblured in GNU Octave. Blur parameters (length and angle) estimated by cepstral method. From left: original, blurred image and deblurred image.
Čeština: Restaurace obrazu rozmazaného vlivem pohybu (Wienerovým filtrem). Naprogramováno v GNU Octave. Parametry pohybu kamery (délka a úhel) odhadnuty kepstrální metodou. Zleva: originál, rozmazaný obrázek a rekonstruovaný obrázek. |
Date | |
Source | Own work |
Author | DaBler |
Licensing
[edit]Public domainPublic domainfalsefalse |
![]() |
I, the copyright holder of this work, release this work into the public domain. This applies worldwide. In some countries this may not be legally possible; if so: I grant anyone the right to use this work for any purpose, without any conditions, unless such conditions are required by law. |
Source code
[edit]- blur_c.m:
## Copyright (C) 2008 David Barina
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{len}, @var{angle}] =} blur_c(@var{image})
## Rozmaze obrazek (odstiny sedi nebo 3 kanaly) pod zadanou delkou a uhlem.
##
## Pokusi se odhadnout delku a uhel rozmazani. Je urcena
## jen pro obrazky poskozene rovnomernym rozmazanim
## po primce.
## @end deftypefn
## Author: David Barina <ibarina@fit.vutbr.cz>
## Created: 2008-11-16
function blur_c(fnamein, fnameout='blurred.png', length=10, angle=0)
% nacist original
IM = imread(fnamein);
IM_IN=double(IM);
% zjistit pocet kanalu
S=size(IM_IN);
if(size(S)(2) == 3)
L=S(3);
else
L=1;
endif
printf("Pocet vrstev obrazu:\n");
L
% horizontalni konvolucni jadro
h=zeros(length,length);
h(1,:) = ones(1,length);
% otocit o dany uhel
hx = imrotate(h,angle,"bicubic","loose",0);
% normalizace
hx ./= sum(hx(:));
% rozmazani obrazku
IM_OUT = conv2(IM_IN(:,:,1), hx, 'valid');
for i = 2:L
IM_OUT(:,:,i) = conv2(IM_IN(:,:,i), hx, 'valid');
endfor
IM_OUT=uint8(IM_OUT);
% ulozi vysledek
imwrite(IM_OUT, fnameout);
endfunction
- detect_c.m:
## Copyright (C) 2008 David Barina
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{len}, @var{angle}] =} detect_c(@var{image})
## Detekuje delku a smer rozmazani z obrazku.
##
## Pokusi se odhadnout delku a uhel rozmazani. Je urcena
## jen pro obrazky poskozene rovnomernym rozmazanim
## po primce.
## @end deftypefn
## Author: David Barina <ibarina@fit.vutbr.cz>
## Created: 2008-11-16
function [a b]=detect_c(im)
% zjisteni poctu kanalu obrazu
S=size(im);
if(size(S)(2) == 3)
L=S(3);
else
L=1;
endif
printf("Pocet vrstev obrazu:\n");
L
% RGB obraz pripadne prevest na intenzitu
if(L == 3)
IMG=double(im)(:,:,1);
IMG(:,:) = 0.299.*double(im)(:,:,1) .+ 0.114.*double(im)(:,:,2) .+ 0.587.*double(im)(:,:,3);
else
IMG=double(im)(:,:,1);
endif
% najit minima/minimum v cepstru
MIN=min(min( real(fftshift(ifft2(log10(abs(fft2(IMG)))))) ));
% na pozici minim dat 1, jinak vsude 0
IMG2=uint8(real(fftshift(ifft2(log10(abs(fft2(IMG))))))<=MIN);
% vyska cepstra
Y=size(IMG2)(1);
%minumum by melo byt ve spodni polovine
IMG3=IMG2(floor(Y/2)+1:Y,:);
% minimum je v horni polovine
if(max(max(IMG3))==min(min(IMG3)))
IMG3 = IMG2(1:floor(Y/2)+1,:);
IMG3 = imrotate(IMG3,180);
endif
% neni minumum?
if(max(max(IMG3))==min(min(IMG3)))
printf("Chyba: Neni minimum ve spektru?!?! Co to znamena???\n");
endif
% zjistit pozici minima
[mx,ix]=max(max(IMG3));
[mx,iy]=max(max(IMG3'));
[sy,sx]=size(IMG3);
ix = ix-1;
iy = iy-1;
% poloha minima vuci stredu
dx = ceil(ix-(sx/2));
dy = iy;
% spocitat vzdalenost od stredu a uhel
delka = abs(dx+dy*i);
uhel = (angle(dx+dy*i)/pi)*180-180;
if(uhel==-180)
uhel=0;
endif
% vratit hodnoty
a = delka;
b = uhel;
endfunction
- deblur_c.m:
## Copyright (C) 2008 David Barina
## -*- texinfo -*-
## @deftypefn {Function File} deblur_c(@var{infilename}, @var{outfilename}, @var{K}, @var{length}, @var{angle})
## Odstrani rozmazani obrazku (stupne sedi nebo barevny).
##
## Pokusi se odhadnout delku a uhel rozmazani. Je urcena
## jen pro obrazky poskozene rovnomernym rozmazanim
## po primce.
## @end deftypefn
## Author: David Barina <ibarina@fit.vutbr.cz>
## Created: 2008-11-16
function deblur_c(fnamein, fnameout='deblur.png', K=1e-2, length=-1, angle=-1)
% nacist obrazek
IM = imread(fnamein);
% zjisteny poctu kanalu (vrstev)
S=size(IM);
if(size(S)(2) == 3)
L=S(3);
else
L=1;
endif
printf("Pocet vrstev obrazu:\n");
L
% originalni obrazek v doublech
IM_BLUR=double( IM );
% zobrazit (prvni kanal pouze)
figure(1); imshow(uint8(IM_BLUR(:,:,1)), [0 255]); title('blurred');
% zjisteni rozmeru obrazku
if(L == 1)
[i1 j1] = size(IM_BLUR);
else
[i1 j1 k1] = size(IM_BLUR);
endif
% pridat okraje kvuli nasobeni ve frekvencni oblasti
IM_BLUR_9 = [repmat(IM_BLUR(1,1,:),i1,j1) repmat(IM_BLUR(1,:,:),i1,1) repmat(IM_BLUR(1,end,:),i1,j1);
repmat(IM_BLUR(:,1,:),1,j1) IM_BLUR repmat(IM_BLUR(:,end,:),1,j1);
repmat(IM_BLUR(end,1,:),i1,j1) repmat(IM_BLUR(end,:,:),i1,1) repmat(IM_BLUR(end,end,:),i1,j1)];
% detekovat poskozeni
printf("Detekovano: \n");
[delka uhel] = detect_c(IM_BLUR)
% pouzit pripadne vynucene parametry
if(length == -1)
length = delka;
endif
length = round(length);
if(angle == -1)
angle = uhel;
endif
printf("Pouziji tyto hodnoty:\n");
K
length
angle
% vytvorit konvolucni jadro simulujici poskozeni
hr=zeros(length,length);
hr(1,:) = ones(1,length);
hrx = imrotate(hr,-angle,"bicubic","loose",0);
hrx ./= sum(hrx(:));
% velikost obrazku i s okrajema
if(L == 1)
[i j]=size(IM_BLUR_9);
else
[i j k]=size(IM_BLUR_9);
endif
% vytvorit filtr simulujici poskozeni
h3=zeros(i,j);
h3(1:size(hrx)(1),1:size(hrx)(2)) = hrx;
H3=fft2(h3);
% vytvorit inverzni filtr ("parametric version of the Wiener filter")
IF=conj(H3)./(abs(H3).^2 + K);
% provest inverzni filtraci (dekonvoluci)
if(L == 1)
IMd=abs(ifft2(fft2(IM_BLUR_9).*(IF)));
else
IMd=abs(ifft2(fft2(IM_BLUR_9(:,:,1)).*(IF)));
IMd(:,:,2)=abs(ifft2(fft2(IM_BLUR_9(:,:,2)).*(IF)));
IMd(:,:,3)=abs(ifft2(fft2(IM_BLUR_9(:,:,3)).*(IF)));
endif
% vyriznout jen puvodni obrazek bez okraju
IMd1 = IMd(1+i1:i1+i1,1+j1:j1+j1,:);
% zobrazit vysledek (jen prvni kanal)
figure(6); imshow( uint8( IMd1(:,:,1) ), [0 255]); title('deblurred');
% ulozi vysledek
imwrite(uint8(IMd1), fnameout);
endfunction
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 03:14, 13 December 2008 | ![]() | 1,464 × 488 (982 KB) | DaBler (talk | contribs) | {{Information |Description={{en|1=Image restoration (motion blur, Wiener filtering). Deblured in GNU Octave. Blur parameters (length and angle) estimated by cepstral method.}} {{cs|1=Restaurace obrazu rozmazaného vlivem pohybu (Wienerovým filtrem). Napr |
You cannot overwrite this file.
File usage on Commons
There are no pages that use this file.
File usage on other wikis
The following other wikis use this file:
- Usage on cs.wikipedia.org
- Usage on de.wikipedia.org
- Usage on en.wikipedia.org
- Usage on fr.wikipedia.org
- Usage on ko.wikipedia.org
- Usage on lv.wikipedia.org
- Usage on pl.wikipedia.org