Asked by TULIKA
on 22 Aug 2014

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?

Answer by Youssef Khmou
on 23 Aug 2014

Accepted answer

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))

Answer by Image Analyst
on 23 Aug 2014

Edited by Image Analyst
on 23 Aug 2014

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);

Show 3 older comments

Image Analyst
on 23 Aug 2014

TULIKA
on 23 Aug 2014

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply Today
## 6 Comments

## Geoff Hayes (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151940#comment_233258

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 (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151940#comment_233273

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

rgb2graythere is the above error.... i want to convert the output into grey scale..... how to do?## Geoff Hayes (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151940#comment_233276

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 (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151940#comment_233278

i didn't code before mesh(imag(F)).i did after this line..that is

## Image Analyst (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151940#comment_233279

F is not a grayscale image! Is this not solved yet? Did you see my solution?

## TULIKA (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/151940#comment_233281

yeah I did..if i send u the complete program will u check the whole program??plzzz...