Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Finding problem in retrieving output images from a function

Asked by Febin Benjamin

Febin Benjamin

on 23 Jul 2013
Accepted Answer by Image Analyst

Image Analyst

This is my code..... The main body accepts images and filter matrix and passes this as inputs to a function called MyFilter.....

m = input('Enter number of rows: ');
n = input('Enter number of columns: ');
for i = 1:m
for j = 1:n
str = ['Enter element in row ' num2str(i) ', col ' num2str(j) ': '];
A(i,j) = input(str);
end
end
fontSize = 20;
for k = 1:25
   tifFilename = sprintf('%d.tif', k);
   if ~exist(tifFilename, 'file')
      fprintf('%s not found.\n', tifFilename);
      continue;
   end
   rgbImage = imread(tifFilename);
   grayImage = rgb2gray(rgbImage );
   BW = Myfilter(grayImage,A);
   figure,imshow(rgbImage);
   title('Color Image', 'FontSize', fontSize);
   figure,imshow(BW);
   title('Binary Edge Image', 'FontSize', fontSize);
end

And this is the function MyFilter which I am calling......

i = imread(grayImage);
filter = A;
[x y] = size(i);
g = double(i);
k= double(i);
h = zeros(256,256);
for xi = 2 : 255
    for yi = 2 : 255
       i(xi,yi)=((g(xi,yi)*filter(2,2) + g(xi,yi-1)*filter(2,1) + g(xi+1,yi-1)*filter(3,1) + g(xi+1,yi)* filter(3,2) + g(xi+1,yi+1)*filter(3,3)+ g(xi-1,yi+1)*filter(1,3)+g(xi-1,yi)*filter(1,2)+ g(xi-1,yi-1)*filter(1,1)+g(xi+1,yi)*filter(3,2)))/2;
       %h(xi,yi)
    end
end

How can i get the images back from the called function after they are processed inside the function?

0 Comments

Febin Benjamin

Febin Benjamin

Products

No products are associated with this question.

2 Answers

Answer by Image Analyst

Image Analyst

on 23 Jul 2013
Accepted answer

Have the first line be

function i = MyFilter(A)

I advise you to use other names for the variables you call "i" and "filter" since they have special built-in meanings for MATLAB and you shouldn't overwrite them with your variables.

1 Comment

Febin Benjamin

Febin Benjamin

on 23 Jul 2013

Where should i write that? In main or Function?

Image Analyst

Image Analyst

Answer by Image Analyst

Image Analyst

on 23 Jul 2013

Have the first line be

function i = MyFilter(A)

I advise you to use other names for the variables you call "i" and "filter" since they have special built-in meanings for MATLAB and you shouldn't overwrite them with your variables.

0 Comments

Image Analyst

Image Analyst

Contact us