How to have image as input for user defined function?

2 visualizzazioni (ultimi 30 giorni)
I am trying to make a user defined function that will segment any image. I need my user defined function to have the input be the file name in single quotes. For example, if my user defined function is called read with my image as cells.tiff, I want the user to be able to do this: read('cells.tiff') and then have it analyze my image. How do I set my input variable in my user defined function and then have it save the image that the user typed as some variable to do the rest of my segmentation?

Risposta accettata

Ameer Hamza
Ameer Hamza il 11 Mag 2018
Just take the filename as an input variable and use imread() to read the image. Here is a general template of your function
function segmentedImage = read(filename)
assert(exist(filename)~=0, sprintf('%s does not exist', filename));
image = imread(filename);
% do segmentation on variable image
segmentedImage = ... % assign your segmented image.
end

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by