How can I make the following heatmap smoother while preserving the contours outlined by the green line?

41 visualizaciones (últimos 30 días)
Hello everyone, I'm a beginner in MATLAB image processing. I currently have the following heatmap, and as you can see, its resolution is quite low. It's made up of many small, jagged color blocks, which makes the image look a bit unrefined. My goal is to make the heatmap smoother while preserving the features outlined by the green line (this is the most important part). I’ve tried using some MATLAB functions for this problem, but although the heatmap becomes smoother, the features enclosed by the green line disappear and merge together, which is a very undesirable outcome. The MATLAB functions I’ve tried include: interp2, imgaussfilt, medfilt2, and imresize. Perhaps due to my inexperience, the actual results haven’t been very good.
The data for the heatmap I plotted is provided in the attachment.

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 21 de Dic. de 2024 a las 16:01
Editada: Cris LaPierre el 21 de Dic. de 2024 a las 16:02
You need to increase the resolution of your data to smooth the apperance. If I couldn't collect the data at higher resolution, I would use interp2 to artificially increase it.
load DataMe.mat
% Use interp2 to increase grid from 30x30 to 100x100
newInd = linspace(1,30);
[X,Y] = meshgrid(newInd);
TPP2 = interp2(TPP,X,Y);
% Create heatmap
h=heatmap(TPP2);
colormap hot
h.GridVisible = 'off';
% Remove tick labels
h.XDisplayLabels = repmat({''}, size(h.XDisplayData));
h.YDisplayLabels = repmat({''}, size(h.YDisplayData));

Más respuestas (2)

John D'Errico
John D'Errico el 21 de Dic. de 2024 a las 17:36
Editada: John D'Errico el 21 de Dic. de 2024 a las 21:53
I don't think interpolating your data will fix the problem, as your data is seriously bumpy.
load DataMe.mat
surf(TPP)
view(32,41)
box on
grid on
Interpolating that mess will not fix it. You cannot make noisy data smoother by interpolating it. It will still have the same bumps in it, though it will look less jagged.
You need to smooth it, but you want to maintain that one contour. Sigh. Smoothing in any form is a process that will see any variation as noise, and then produce a surface with less variation. But any transitions will be interpreted as potentially noise too. So any smoothing you do will tend to kill off the shape of that contour.
Could a smoothing tool be written that would maintain a given contour? Well, yes, I know that to be true. For example, my gridfit utility (found on the File Exchange) can smooth a surface like your data. And I did once show such a tool (in 3-d) can be modified to follow a general prescribed path. The code itself gets a bit nasty, since you would need to define that path, then build the linear system to incorporate that path as a constraint. Possible, but it takes some work. And the path constraint introduces other artifacts into the fit itself, which makes the result less than a happy one.
A big problem is, that contour you show includes a very narrow (and deep) valley. And as soon as you start to smooth the surface, that valley starts to disappear.
Here, I've overlayed a mesh (in red) of a smoothed version of the surface on top of the old one.
But there is no simple way to control what happens along that curved path you have indicated. I don't know what contour level you chose, else I could show how the shape of that same contour has changed. Anyway, any contour plot of your original data will be quite bumpy, so the curve you have drawn surely does not come from a contour taken from that noisy data.

Paul
Paul el 21 de Dic. de 2024 a las 17:42
If you don't need specific features of heatmap, perhaps a pcolor with shading would be useful
load DataMe
pcolor(flipud(TPP)),shading interp
colormap('hot'),colorbar

Categorías

Más información sobre Colormaps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by