convolution of the two image

i have to code convolution of the two image(the greyimage output and the image i posted)(once in space domain and again in frequency domain using fft2 and ifft2)there is no error in the code but it didn't give proper output...please let me know where i'm going wrong in the coding...
x= 1:256;y=1:256;
[p,q]=freqspace(256);
[X,Y]=meshgrid(p,q);
R=(X.^2 + Y.^2);
Lambda=10*10^-9;
dis=4*10^-2;
F = (exp(i.*pi.*R))./(Lambda.*dis);
grayImage = imag(F);
mesh(grayImage);
imshow(grayImage, []);
colormap(gray(256));
A=imread('image.jpg');
R=A(:,:,1);
G=A(:,:,2);
B=A(:,:,3);
igray=rgb2gray(A);
A1=im2double(igray);
I=conv2(A1,grayImage);
figure,imshow(I,'InitialMagnification','fit');

2 Comments

Please attach image.jpg or give us a standard demo image we can use instead.
i posted but didn't showed it.i hope this time it upload the image

Sign in to comment.

 Accepted Answer

Image Analyst
Image Analyst on 23 Aug 2014
This seems like two separate programs - the top half does stuff with F, then the bottom half ignores F and does stuff with image.jpg and gray scale versions of it. Are they supposed to be related in anyway? You're basically convolving A with itself, which is the autocorrelation and will give you a strong central spike with steep sides. What do you think the proper output should be? Are you sure you want an autocorrelation of A or do you want to convolve A with F? Please supply more information and images.

5 Comments

Yes Sir i have to convolve with greyscale image of F and image A....please tell me how to do this .i don't want to do any auto-correlation.the output should be like hazy image of concentrating circles or it may overlap.in both process (space domain and frequency doamin) the output should be same.i dont know properly matlab that's why whatever program i write i'm posting it here
TULIKA, don't accept an answer until it answers your question. Try this code:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
x= 1:150;y=1:150;
[p,q]=freqspace(150);
[X,Y]=meshgrid(p,q);
R=(X.^2 + Y.^2);
Lambda=633*10^-9;
dis=10*10^-3;
F = (exp(i.*pi.*R))./(Lambda.*dis);
% Convert into a gray scale image and display it as a mesh.
subplot(2, 3, 1);
kernel = imag(F); % Gray scale image = imaginary part.
mesh(kernel);
axis square
title('Convolution Kernel', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Display grayscale image.
subplot(2, 3, 2);
imshow(kernel, []);
axis on;
title('Convolution Kernel', 'FontSize', fontSize);
colormap(gray(256));
colorbar;
% Convert into a color image, just for fun
rgbImage = ind2rgb(uint8(255*mat2gray(kernel)), jet(256));
subplot(2, 3, 3);
imshow(rgbImage, []);
axis on;
title('RGB Image of kernel', 'FontSize', fontSize);
rgbImage = imread('peppers.png');
subplot(2, 3, 4);
imshow(rgbImage);
axis on;
title('Original Color Image', 'FontSize', fontSize);
% R=rgbImage(:,:,1);
% G=rgbImage(:,:,2);
% B=rgbImage(:,:,3);
grayImage = rgb2gray(rgbImage);
subplot(2, 3, 5);
imshow(grayImage, []);
axis on;
title('Grayscale Image', 'FontSize', fontSize);
% Filter the gray scale image.
filteredImage = conv2(double(grayImage), kernel);
subplot(2, 3, 6);
imshow(filteredImage, []);
axis on;
title('Filtered Image', 'FontSize', fontSize);
ok..thanks for the suggestion
if you don't mind may i know in my coding where i was going wrong...i want to clear confusion...even in my coding i also doubled the image separately....why it was being auto-correlated?why my program is not working??
and Thanks it works....
is it necessary to have the same dimension iin multiplying the two iamges in frequency domain?
Well the main reason you didn't get any good display is because you didn't use [] in imshow so any values more than 1 just got clipped to 1. Several other problems/issues (though nothing major though and some just a matter of style), so I just did it correct from scratch.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!