help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to display an image having imaginary part


From: Juan Pablo Carbajal
Subject: Re: how to display an image having imaginary part
Date: Wed, 5 Dec 2012 10:40:40 +0100

On Wed, Dec 5, 2012 at 10:21 AM, preethi k <address@hidden> wrote:
> hi all,
>         While doing the wiener filter in image processing imshow shows
> warning when displaying a image having imaginary part. I didn't get the
> result. How can we display a image having imaginary part. Following is my
> code.
>
> %wiener
> close all;
> clear all;
> clc;
>
>
> a=imread('/home/preethi/diplab/Images/lenna.jpg');
> x=double(a);
> h=[0 .05 .05 0;.15 .1 .1 .15;.0 .1 .1 .0;0 .1 .1 0];
> [m n]=size(x);
> gmn=conv2(x,h);
> [m1 n1]=size(gmn);
> %without noise
> hkl=fft2(h,m1,n1);
> gkl=fft2(gmn);
> x=gmn;
> sigma2x=var(var(x));
> hkkl=conj(hkl);
> hkl2=hkl.*hkkl;
> denom=hkl2;
> g1kl=hkkl./denom;
> fmn=ifft2(gkl.*g1kl);
> figure, subplot(131),imshow(a),title('original image');
> subplot(132),imshow(uint8(gmn)),title('degraded image');
> subplot(133),imshow(abs(fmn)),title('restored image');
> %with noise
> gmn=imnoise(uint8(gmn),'gaussian');
> hkl=fft2(h,m1,n1);
> gkl=fft2(gmn);
> x=gmn;
> sigma2w=(var(var(x)));
> er=sigma2x/sigma2w;
> hkkl=conj(hkl);
> hkl2=hkl.*hkkl;
> denom=hkl2+er;
> g1kl=hkkl./denom;
> fmn=ifft2(gkl.*g1kl);
> figure, subplot(131),imshow(a),title('original image');
> subplot(132),imshow(uint8(gmn)),title('degraded image with noise');
> subplot(133),imshow(fmn),title('restored image');
>
>
> --Thanks
> Preethi
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>

First,

hkl=fft2(h,m1,n1);
hkkl=conj(hkl);
hkl2=hkl.*hkkl;

Could be replaced with
hkl   = fft2 (h,m1,n1);
hkl2 = abs (hkl).^2;

The function abs takes the modulus of the imaginary numbers, and it
seems your are not using the other variables.

Regarding the imaginary part. It seems you are recovering and image
after some manipulations of it fft. This could generate an ifft that
has small imaginary parts. check how big is the imaginary part, for
example
fmn = ifft2 (gkl.*g1kl);

figure;
subplot (121);
imshow (real (fmn));
title ('Real part');

subplot (122);
imshow (imag (fmn));
title('Imaginary part');


reply via email to

[Prev in Thread] Current Thread [Next in Thread]