how to make a function with three parameter
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello everyone
I am trying to create a function with three inputs: two images, and id of patient...I can not do
main.m
image1='c:\image1.bmp';
image2='c:\image2.bmp';
id=1;
result=delta(image1,image2,id);
delta.m
function delta(image1,image2,id)
im1=imread(image1);
im2=imread(image2);
it's just an example
0 comentarios
Respuestas (2)
Wayne King
el 20 de Jul. de 2014
Editada: Wayne King
el 20 de Jul. de 2014
Just declare the function
function [output] = DescriptiveNameHere(image1,image2,patientID)
. . . end
save it in a folder and add that folder to the MATLAB path.
You then just call that function at the command line.
>> output = DescriptiveNameHere(image1,image2,patientID);
See the information here:
You can write your function so that it accepts an image name, or the path to the image plus the image name.
Write your function to accept string input arguments.
0 comentarios
Image Analyst
el 20 de Jul. de 2014
I don't know what ID or delta is but maybe delta is the difference image
function diffImage = delta(image1, image2, id)
diffImage = []; % Initialize
try
% First check that image1 and image2 exist with the exist() function.
if ~exist(image1)
message = sprintf('Error. Image file does not exist:\n%s', image1);
uiwait(warndlg(message));
return;
end
if ~exist(image2)
message = sprintf('Error. Image file does not exist:\n%s', image2);
uiwait(warndlg(message));
return;
end
im1=imread(image1); % image1 is a filename string, not an image!
im2=imread(image2);
% Check that dimensions of the two images match.
[rows1, columns1, numberOfColorChannels1) = size(im1);
[rows2, columns2, numberOfColorChannels2) = size(im2);
if row1~=rows2 || columns1~=columns2 || numberOfColorChannels1 ~= numberOfColorChannels2
message = sprintf('Error. Image dimensions do not match!');
uiwait(warndlg(message));
return;
end
% Now do the subtraction.
diffImage = double(im1) - double(im2);
% Now, not sure what to do with "id" that you passed in.
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(1, '%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!