Manipulate '1' values in binary matrix

1 view (last 30 days)
Ana
Ana on 3 Jan 2015
Commented: Ana on 4 Jan 2015
I have a binary matrix and I need to create a convolving function that manipulates only the '1' values. In other words, I want to create second matrix where the '0' values remain in the same place but the '1' values are replaced with the output of the function that manipulated them. Any thoughts?

Accepted Answer

Image Analyst
Image Analyst on 3 Jan 2015
Just create a mask for the zeros and multiply your output by the mask
% Create mask
mask = originalMatrix == 0;
% Do the convolving with conv2d() or any custom function you want
% to get some new matrix.
newMatrix = conv2d(originalMatrix, yourKernel, 'same');
% Put zeros of original back in
newMatrix(mask) = 0;
  1 Comment
Ana
Ana on 4 Jan 2015
Thank you Image Analyst! Both answers were very helpful.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!