image - In matlab, how to 'smooth' pixels in 2D heatmap using imagesc -


using matlab, have matrix (data) , plotting using imagesc(data) produce heatmap:

data = [1 1 1 1 1 1 1 1 1 1; 1 1.04 1.04 1.04 1.03 1 1.01 1.01 1.03 1.01; 1.36 1.3 1.25 1.2 1.15 1.1 1.2 1.13 1.07 1.11; 3.65 3.16 2.94 2.68 2.39 2.22 2.17 1.95 1.79 1.81; 5.91 5.75 5.47 5.3 4.98 4.79 4.62 4.55 4.38 4.19; 6 6 5.99 5.83 5.49 5.33 5.14 4.94 4.77 4.74]; imagesc(data) 

enter image description here

is there way 'smooth' pixels in order produce more this: enter image description here

interp2 may of use here. use data key points, create finer grid of points span same width , height , interpolate in between key points.

something this:

%// define data data = [1 1 1 1 1 1 1 1 1 1; 1 1.04 1.04 1.04 1.03 1 1.01 1.01 1.03 1.01; 1.36 1.3 1.25 1.2 1.15 1.1 1.2 1.13 1.07 1.11; 3.65 3.16 2.94 2.68 2.39 2.22 2.17 1.95 1.79 1.81; 5.91 5.75 5.47 5.3 4.98 4.79 4.62 4.55 4.38 4.19; 6 6 5.99 5.83 5.49 5.33 5.14 4.94 4.77 4.74];      %// define integer grid of coordinates above data [x,y] = meshgrid(1:size(data,2), 1:size(data,1));  %// define finer grid of points [x2,y2] = meshgrid(1:0.01:size(data,2), 1:0.01:size(data,1));  %// interpolate data , show output outdata = interp2(x, y, data, x2, y2, 'linear'); imagesc(outdata);  %// cosmetic changes axes set(gca, 'xtick', linspace(1,size(x2,2),size(x,2)));  set(gca, 'ytick', linspace(1,size(x2,1),size(x,1))); set(gca, 'xticklabel', 1:size(x,2)); set(gca, 'yticklabel', 1:size(x,1));  %// add colour bar colorbar; 

the code that's @ bottom required because defining finer grid increases size of image. need relabel axes go original size.

we this:

enter image description here

small note

i'm using matlab r2014a, , default colour map jet. you're using r2014b+ , default colour map parula. won't same colour distribution me, smoothness desire.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -