How can I vectorize the following code?
1 回表示 (過去 30 日間)
古いコメントを表示
main.m
I = imread('bear.png');
J = rgb2gray(imread('marked_bear.png'));
mask = I-J;
for r=1:size(I,1)
for c=1:size(I,2)
if(mask(r,c))
I = some_function(I, r, c);
end
end
end
imshow(I);
some_function.m
function I = some_function(I, r, c)
% some processing on image 'I'
I(r,c) = 255;
bear.png
marked_bear.png
0 件のコメント
採用された回答
Image Analyst
2017 年 7 月 28 日
Like this:
I = imread('bear.png');
J = rgb2gray(imread('marked_bear.png'));
mask = I-J; % Weird, but okay...whatever.
I(mask~=0)=255;
4 件のコメント
Image Analyst
2017 年 7 月 29 日
OK, then...
function I = some_function(I, J)
mask = I - J;
I(mask ~= 0) = 255;
There. It's vectorized, still has a function, and that function is called "some_function" (instead of MaskI as I had called it), just like you asked for.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Author Block Masks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!