帶矩陣的圖像疊加 (Image overlay with matrix)


問題描述

帶矩陣的圖像疊加 (Image overlay with matrix)

I have an image (png) that I want to put underneath a heatmap(so to speak) made from a and a 2D matrix of values 0-1. So the intensity of the spot would be decided by how large the value in the matrix is. 

I can use imshow(matrix) but that completely draws over the image underneath. Is it possible to perhaps, not draw any pixels with matrix values <.05 or some other way to make this work?


參考解法

方法 1:

Here is an example of overlaying a binary heatmap on top of 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);
[X Y] = meshgrid(1:r,1:c);
Z = mvnpdf([X(:) Y(:)], [r c]./2, diag(15.*[r c]));
Z = (Z-min(Z(:)))./range(Z(:));
Z = reshape(Z',[c r])';

%# 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

方法 2:

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

(by MichaelAmroBlessedKey)

參考文件

  1. Image overlay with matrix (CC BY-SA 3.0/4.0)

#matlab #matlab-figure






相關問題

MATLAB:多線程和多核之間的區別 (MATLAB: difference between Multithreading and Multicore)

在 matlab 中用 imread 讀取圖像文件會給出什麼樣的表示? (reading a image file with imread in matlab gives what kind of representation?)

Як прызначыць індывідуальныя пазнакі значэнняў на восях у Matlab? (How to assign individual labels to values on the axes in Matlab?)

覆蓋 MATLAB 默認靜態 javaclasspath 的最佳方法 (Best way to override MATLAB's default static javaclasspath)

如何在 Matlab 中為這個 3D 繪圖設置動畫? (How to animate this 3D plot in Matlab?)

如何轉換 x = [x_de,x_nu]; 從matlab到python? (How do I convert x = [x_de,x_nu]; from matlab to python?)

opnet 和 matlab 接口 (opnet and matlab interfacing)

Matlab:使用正非整數邊緣權重執行最小切割 (Matlab: perform min cut with positive non-integer edge weights)

帶矩陣的圖像疊加 (Image overlay with matrix)

在矩形 [a,b]x[c,d] 上離散最小二乘逼近。使用函數 1,x,y,sin(x) 和 sin(y) 作為基礎 (Discete least sqauare approximation on rectangle [a,b]x[c,d].Use functions 1,x,y,sin(x) and sin(y) as the basis)

如果這個變量在調用之間發生了變化,為什麼匿名函數的固定參數沒有更新? (Why is fixed argument of anonymous function not updated, if this variable has changed between calls?)

在 MATLAB 中通過 HTTP 接收數據 (Receive data via HTTP in MATLAB)







留言討論