how to make a function with three parameter
조회 수: 6 (최근 30일)
이전 댓글 표시
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
답변 (2개)
Wayne King
2014년 7월 20일
편집: Wayne King
2014년 7월 20일
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
Image Analyst
2014년 7월 20일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!