How to take Image as Input in a function

22 views (last 30 days)
Talal Waseem
Talal Waseem on 31 Mar 2020
Commented: Ella on 6 Jun 2023
Im trying to make a function that takes a image of any type (png,jpeg etc) and then performs some task on them. But i cannot figure how to take the image as input in the function. Please help :)

Answers (2)

Cris LaPierre
Cris LaPierre on 31 Mar 2020
You'd have to first load the image into MATLAB and store it in a variable. You can then pass that variable as input to your function.
Here's the link to a doc page on importing images.
  5 Comments
Ella
Ella on 5 Jun 2023
I also made sure that the image is downloaded into the proper file
Cris LaPierre
Cris LaPierre on 5 Jun 2023
Edited: Cris LaPierre on 5 Jun 2023
Share the code you have written (including loading your image) that calls/uses your function.

Sign in to comment.


Image Analyst
Image Analyst on 6 Jun 2023
For example
grayImage = imread('moon.tif');
meanGL = mean2(grayImage)
meanGL = 52.9154
grayImage2 = DarkenImage(grayImage); % Call function
meanGL2 = mean2(grayImage2)
meanGL2 = 26.7118
%======================================================
% Define function that divides the image values by 2
function output = DarkenImage(inputImageArray)
output = inputImageArray / 2;
end

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!