help with calling a function on matlab

2 ビュー (過去 30 日間)
Teshan Rezel
Teshan Rezel 2022 年 8 月 22 日
回答済み: rumin diao 2022 年 8 月 22 日
Hi folks,
I have the following code but am getting an error when trying to run it! I think it is due to the custom function I have defined but not certain how to get around this.
Below is my code:
i = 1000;
x = im2gray(imread([path, num2str(i), '.png']));
imshow(x);
bw1 = edge(x, 'Sobel');
bw2 = edge(x, 'Prewitt');
bw3 = edge(x, 'Roberts');
bw4 = edge(x, 'log');
bw5 = edge(x, 'zerocross');
bw6 = edge(x, 'Canny');
bw7 = edge(x, 'approxcanny');
t = myMask(bw1);
figure;
subplot(3, 3, 1);imshow(bw1);title('Sobel');
subplot(3, 3, 2);imshow(bw2);title('Prewitt');
subplot(3, 3, 3);imshow(bw3);title('Roberts');
subplot(3, 3, 4);imshow(bw4);title('log');
subplot(3, 3, 5);imshow(bw5);title('zerocross');
subplot(3, 3, 6);imshow(bw6);title('Canny');
subplot(3, 3, 8);imshow(bw7);title('approxcanny');
function test = myMask(bw)
bw = bwareaopen(bw, 500);
bw = imfill(bw, 'holes');
bw = bwperim(bw);
bw = imdilate(bw, ones(5));
bw = imerode(bw, ones(3));
bw = imfill(bw, 'holes');
end
and the error I get it:
Output argument "test" (and maybe others) not assigned during call to "edge detection test>myMask".
  1 件のコメント
Stephen23
Stephen23 2022 年 8 月 22 日
Change the output argument to "bw":
function bw = myMask(bw)
% ^^

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

採用された回答

rumin diao
rumin diao 2022 年 8 月 22 日
you defined the function by using 'test = myMask(bw)' which means the function will returns a variable 'test', but in it, you didnt define'test' and there isnt a statement about returning 'test'.
so what you actually need to return is 'bw' and define the function by 'bw = myMask(bw)'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by