MATLAB: Create image from overlay

image overlayimshowimwrite

Good morning,
I am writing a code in which i combine the result of a density field with an image. I used image overlay and imshow to show them but i would like create a real image from what i see in imshow.
imshow(screen); %screen is the background image
hold on
OverlayImage = imshow( trmp ); %trmp is the density field
caxis auto
colormap( OverlayImage.Parent, jet );
colorbar( OverlayImage.Parent );
rslt=set(OverlayImage, 'AlphaData', 0.4 );
Can somebody help me with this?

Best Answer

One way is just to print the figure window after you have overlayed both images using your code
mshow(screen); %screen is the background image
hold on
OverlayImage = imshow( trmp ); %trmp is the density field
caxis auto
colormap( OverlayImage.Parent, jet );
colorbar( OverlayImage.Parent );
rslt=set(OverlayImage, 'AlphaData', 0.4 );
print -djpeg filename
This will create a JPG image, will you can read using imread function. However, due to JPEG comression, you might not want this solution.
In that case you can try to use imfuse function: https://www.mathworks.com/help/images/ref/imfuse.html
img_overlay = imfuse(screen, trmp);
Related Question