How to soften the boundaries within a matrix
1 view (last 30 days)
Show older comments
Andres Salomon Fielbaum Schnitzler
on 21 Feb 2022
Edited: Andres Salomon Fielbaum Schnitzler
on 22 Feb 2022
Hi
I have a matrix M, size N1xN1, which only has positive integers, and is delimited by zones, as seen in the following picture created using image(M) (I changed the colormap and the axes, but that is not relevant for this question)
What I would like to know if there is a way to soften the boundaries between each area, i.e., that the curves do not seem discretized, but interpolated.
Thanks in advnace for any help
0 Comments
Answers (1)
Image Analyst
on 21 Feb 2022
You can blur the matrix and rediscretize it.
windowWidth = 9;
kernel = ones(windowWidth) / windowWidth^2;
blurredImage = conv2(M, kernel, 'same');
% Now call discretize to quantize into the levels you had.
7 Comments
Image Analyst
on 21 Feb 2022
Again, attach M in a .mat file with the paperclip icon.
save('answers.mat', 'M');
Make it easy for me to help you. I'll check back in a couple hours.
In the meantime I'm attaching a demo where you can get the boundaries with bwboundary() and then smooth the boundary with a Savitzky-Golay filter.
Andres Salomon Fielbaum Schnitzler
on 22 Feb 2022
Edited: Andres Salomon Fielbaum Schnitzler
on 22 Feb 2022
See Also
Categories
Find more on Digital Filter Analysis in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!