How to take Image as Input in a function

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 :)

回答 (2 件)

Cris LaPierre
Cris LaPierre 2020 年 3 月 31 日

1 投票

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 件のコメント

Talal Waseem
Talal Waseem 2020 年 4 月 1 日
figured it out thanks to you! Cheers
YOGITAA YOGITAA
YOGITAA YOGITAA 2022 年 10 月 5 日
how did you solve it? I have the same question.
Ella
Ella 2023 年 6 月 5 日
I'm struggling with the same thing. I know my code works, because when I remove the function header and the code with a specific image inserted in the imread funciton the code works. It only stops working when I try to run it as a function. This is my function header.
function Organize(fn)
%code
end
How would I call the function with the image being the fn input?
Ella
Ella 2023 年 6 月 5 日
I also made sure that the image is downloaded into the proper file
Cris LaPierre
Cris LaPierre 2023 年 6 月 5 日
編集済み: Cris LaPierre 2023 年 6 月 5 日
Share the code you have written (including loading your image) that calls/uses your function.

サインインしてコメントする。

Image Analyst
Image Analyst 2023 年 6 月 6 日

0 投票

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

1 件のコメント

Ella
Ella 2023 年 6 月 6 日
I managed to figure it out! Thank you for your help

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeImage Processing Toolbox についてさらに検索

製品

リリース

R2018a

質問済み:

2020 年 3 月 31 日

コメント済み:

2023 年 6 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by