Borrar filtros
Borrar filtros

How can I vectorize the following code?

1 visualización (últimos 30 días)
Ba Ba Black Sheep!
Ba Ba Black Sheep! el 28 de Jul. de 2017
Comentada: Image Analyst el 29 de Jul. de 2017
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

Respuesta aceptada

Image Analyst
Image Analyst el 28 de Jul. de 2017
Like this:
I = imread('bear.png');
J = rgb2gray(imread('marked_bear.png'));
mask = I-J; % Weird, but okay...whatever.
I(mask~=0)=255;
  4 comentarios
Ba Ba Black Sheep!
Ba Ba Black Sheep! el 29 de Jul. de 2017
I was talking about retaining some_function().
Image Analyst
Image Analyst el 29 de Jul. de 2017
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.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by