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);
mesh(imag(F));
there is an ouput which i have to convert into gray image.
HOW to convert into gray image...i have an error
Map myst be m*3 matrix?
how will i do this?

6 Kommentare

Geoff Hayes
Geoff Hayes am 23 Aug. 2014
Tulika - which output are you converting into a gray image? Are you using the rgb2gray to convert the image from RGB to grayscale? Which line of code is generating the error (since all of the above code runs smoothly)?
TULIKA
TULIKA am 23 Aug. 2014
Bearbeitet: TULIKA am 23 Aug. 2014
thanks for checking...yeah it runs smoothly but the output of the program is an colored output.....when i convert this output to grey color with rgb2gray there is the above error.... i want to convert the output into grey scale..... how to do?
Geoff Hayes
Geoff Hayes am 23 Aug. 2014
Tulika - how are you converting the output of the program to grayscale? What lines of code follow the above which ends with mesh(imag(F));?
TULIKA
TULIKA am 23 Aug. 2014
i didn't code before mesh(imag(F)).i did after this line..that is
F1=rgb2gray(F)
so there is an error .....
Map must be m*3 matrix?
how to apply before mesh(imag(F))
i'm new to matlab.i didn't konw so much coding...
Image Analyst
Image Analyst am 23 Aug. 2014
F is not a grayscale image! Is this not solved yet? Did you see my solution?
TULIKA
TULIKA am 23 Aug. 2014
yeah I did..if i send u the complete program will u check the whole program??plzzz...

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Youssef  Khmou
Youssef Khmou am 23 Aug. 2014

0 Stimmen

This is numeric problem, no need for images processing tools, in fact you are computing a type of two dimensional exponential function, you have many ways to visualize your function :
figure; surface(abs(F))

2 Kommentare

TULIKA
TULIKA am 23 Aug. 2014
Bearbeitet: TULIKA am 23 Aug. 2014
the output of the program is an coloured output.....when i convert this output to grey colour with rgb2gray there is an error.... i want to convert the output into grey scale..... plzz help
Youssef  Khmou
Youssef Khmou am 25 Aug. 2014
try the following command :
colormap gray

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 23 Aug. 2014
Bearbeitet: Image Analyst am 23 Aug. 2014

2 Stimmen

TULIKA, I know you already accepted an answer, so maybe you don't need my answer anymore, but I had this already to post and then I got to watching a movie and didn't post it until now. Well, for whatever it's worth, here it is. If it helps in any way, maybe you can vote for it:
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 = 13;
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(1, 3, 1);
grayImage = imag(F); % Gray scale image = imaginary part.
mesh(grayImage);
axis square
title('Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Display grayscale image.
subplot(1, 3, 2);
imshow(grayImage, []);
title('Grayscale Image', 'FontSize', fontSize);
colormap(gray(256));
colorbar;
% Convert into a color image, just for fun
rgbImage = ind2rgb(uint8(255*mat2gray(grayImage)), jet(256));
subplot(1, 3, 3);
imshow(rgbImage, []);
title('RGB Image', 'FontSize', fontSize);

6 Kommentare

TULIKA
TULIKA am 23 Aug. 2014
Bearbeitet: TULIKA am 23 Aug. 2014
THANK U SO MUCH.THOUGH I ACCEPTED ANSWER BUT YOUR REPLY REALLY HELPED ME A LOT.AND HOW MUCH U DONT KNOW..AGAIN THANKS
TULIKA
TULIKA am 23 Aug. 2014
Bearbeitet: TULIKA am 23 Aug. 2014
if i send u the complete program will u check the whole program?? here it is
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');
i don't know the output is right or not..
plzz plzz
Image Analyst
Image Analyst am 23 Aug. 2014
You forgot to attach image.jpg, so I can't read in the badly-named "A". Can you just use a standard demo image like peppers.png or something?
TULIKA
TULIKA am 23 Aug. 2014
this is the image
Image Analyst
Image Analyst am 23 Aug. 2014
You're basically convolving that image with itself, which is an autocorrelation, so you should see a spike at the middle, followed by a rapid fall off. Of course the second half of your code has nothing to do with the first half of your code. What are you attempting to achieve? Perhaps you should start a new discussion if we're going to be talking about new topics of convolution or autocorrelation or spatial filtering, as you've already marked this one as Accepted and many people may not bother to look anymore.
TULIKA
TULIKA am 23 Aug. 2014
Sir,i'm new to matlab,even i don't know so much coding and didn't understand what you have said.I have to code the convolution of the two images i.e the output of the program and the image (i have sent)one in space domain and another frequency domain,yeah i have unintentionally clicked that option and it accepted the answer... there is no error in the program but output figure is unexpected and the two outputs in space domain convolution and in frequency domain convolution are to be same...

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by