Heatmap overlay disappears when I change the caxis.

I am attempting to overlay a heatmap on an image of a circuit built on a breadboard. I can get the heat spots to appear if I comment out the caxis([0 200]) line of code, but the color bar is then incorrect. If I uncomment the caxis([0 200]) the color bar scale is correct but the heat spots on the image disappear. The second image attached is how I need the heat spots to look, and the third image is how I need the colorbar to look. How can I get both working?
close all
clc
%%SHOW IMAGE
buck_regulator = imread('bb_image.jpg');
[height,width,depth] = size(buck_regulator);
%%SET TEMPERATURES
temperature = zeros(3024, 4032);
temperature(2152, 3420) = 50;
temperature(1942, 2920) = 90;
temperature(2510, 2845) = 90;
%%CREATE GAUSSIAN KERNEL
gaussian_kernel = fspecial('gaussian', [850 850], 150);
% Apply gaussian filter on given data
density = imfilter(temperature, gaussian_kernel, 'replicate');
%%Overlay the heatmap onto the image
imshow(buck_regulator);
hold on
x = imshow(density, []);
x.AlphaData = 0.5;
colormap(jet);
h = colorbar;
caxis([0 200]); % If i uncomment this line, the overlay doesn't work
set(h, 'ylim', [0 200]);

Answers (0)

Categories

Asked:

on 29 Apr 2018

Edited:

on 29 Apr 2018

Community Treasure Hunt

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

Start Hunting!