Image overlay

I have an image (png) that I want to put under thermal insulation (so to speak) from a and a 2D matrix of values ​​0-1. Thus, the intensity of the spot will be determined by how large the value in the matrix.

I can use imshow (matrix), but it completely draws the image under it. Is it possible, perhaps, not to draw pixels with matrix values ​​<0.05 or in some other way to do this?

+6
source share
2 answers

Here is an example of overlaying a binary heatmap over a color image:

%# some image I = im2double( imread('peppers.png') ); %# I create here a random mask (gaussian centered in middle of image) [r,c,~] = size(I); [XY] = meshgrid(1:r,1:c); Z = mvnpdf([X(:) Y(:)], [rc]./2, diag(15.*[rc])); Z = (Z-min(Z(:)))./range(Z(:)); Z = reshape(Z',[cr])'; %# show image and mask separately subplot(121), imshow(I) subplot(122), imshow(Z) %# show overlayed images figure, imshow(I), hold on hImg = imshow(Z); set(hImg, 'AlphaData', 0.6); %# also we can specify a colormap colormap hsv 

enter image description hereenter image description hereenter image description here

+7
source

the loaded png will be a three-dimensional matrix. You can convert 2d binary matrix to 3d with repmat. Then resize the binary matrix so that it is the same size as png with imresize. Finally, you can show two matrices mixed with something like imshow (alpha (myPng) + (1-alpha) * (myBinaryMat)), where alpha is the blending parameter between 0 and 1.

+1
source

Source: https://habr.com/ru/post/891664/


All Articles