how can give an image as input in a fuction?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hi I want to define a function that every time that I call it, it get an image address and do some process on this image I don't want to use 'input.tif' because I want to use this function in a loop and use the result of this for the next image...
if true
function [ maskedImage] = myprog(folder,baseFileName)
fullFileName = fullfile(folder, baseFileName);
grayImage = imread(fullFileName);
....
end
end
4 comentarios
Image Analyst
el 19 de Sept. de 2014
Editada: Image Analyst
el 19 de Sept. de 2014
We don't know what line 29 is. You forgot to post the error message - you just snipped out an almost useless part of it. Please post ALL the red text - don't snip out part of it or paraphrase it, just give it exactly. Presumably you called it with an actual names of some folder and file and didn't pass in 'folder' and 'baseFileName.tif'.
Respuestas (4)
Image Analyst
el 21 de Sept. de 2014
In myprog(), you have this line:
clear; % Erase all existing variables. Or clearvars if you want.
you must remember to never, ever have that in a function . If you use it, it must be in a script . What happens is that when you call clear, it wipes out the filename that you passed in.
Iain
el 19 de Sept. de 2014
Ok, if by "image" you mean filename, then you can do it like this:
folder = 'C:\My Images\';
files = dir([folder '\*.jpg']);
for i = 1:numel(files)
filename = [folder files(i).name];
% ... etc etc
end
1 comentario
David Young
el 19 de Sept. de 2014
It's more robust to use
filename = fullfile(folder, files(i).name);
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!