MATLAB: Combine Two Grayscale Images With Different Alpha

I started writing a program in MATLAB to overlay two grayscale images of same size with different alpha dynamically. Therefore both images are plotted in one figure and beneath them is a slider with which the alpha of the second image can be increased from zero to one. So when moving the slider one can actually sees the two images blending. Suppose the slider is at 0.3 then the 'AlphaData' of the second image is set to 0.3, while the 'AlphaData' of the first image is always 1. On the screen I now see an image, which is a combination of these two images.

Now I want to get exactly this image from the figure (with the same size, as the images before) and work with it. But I have no idea how to do it.


Grayscale image is just array of numbers. Depending on how you get the data it could be 0~1 or 1~255. Overlaying two images is merely adding the numbers. Blending two images is merely computing their weighted sum.

clear;clc;close all I1_rgb = imread('peppers.png'); I1_gray = rgb2gray(I1_rgb); figure(1) imshow(I1_gray) I2_gray = imread('coins.png'); I2_gray = padarray(I2_gray, size(I1_gray)-size(I2_gray), ... 'circular', 'post'); figure(2) imshow(I2_gray) alpha = .3; % this can be dynamically adjusted by a slider O1 = I1_gray + I2_gray*alpha; % overlay figure(3) imshow(O1) O2 = I1_gray*(1-alpha) + I2_gray*alpha; % blend figure(4) imshow(O2) <hr>

For mixing colored images, see my answer at MATLAB: Applying transparent mask over an RGB image and blending with another


  • Load Texture2D from Stream with RenderTarget2D, Textures disapear after game window minimizing
  • What is the formula for extracting the src from a calculated blendmode?
  • how to apply alpha layer mask to make some of the image transparent using canvas
  • Hue effect for Image - iOS
  • Assigning {pointer to function with C linkage} to {pointer to function with C++ linkage} and vice ve
  • CDI: Injecting single instance works, but injecting Instance does not. Why?
  • How read between delimiters in php DOM of a XML file?
  • PHP: Very simple Encode/Decode string
  • How to know if a JFrame is on screen in a multi screen environment
  • css calendar - td background diagonal split - two colors
  • SQL Server re-calculate or not?
  • Are there “Dynamic Playlists” of unit tests in Visual Studio?
  • Selectively hide background elements when overlayed with transparent div
  • Watson Conversation - Why is the ANYTHING ELSE node not chosen
  • Xmonad multiple submap key combos
  • Activation Function choice for Neural network
  • Can I have a variable number of URI parameters or key-value pairs in Laravel 4?
  • VBA Excel, loop through variables
  • Application level floating views with navigation in Android
  • as3-flash: any way to access all the instances placed in different frames from document class?
  • AndEngine Applying Transparancy to AndEngine View
  • Using a canvas object in a thread to do simple animations - Java
  • why xml file does not aligned properly after append the string in beginning and end of the file usin
  • Does it make sense to call System.gc() and Thread.sleep() when working on Bitmaps?
  • jQuery ready not fired after rails link_to is clicked
  • htaccess add www if not subdomain, if subdomain remove www
  • Caching attributes in superclass
  • How to modify the colors in the legend of a plot using a fill gradient?
  • Mysterious problem with floating point in LISP - time axis generation
  • JSON response opens as a file, but I can't access it with JavaScript
  • Yii2: Config params vs. const/define
  • Avoid links criss cross / overlap in d3.js using force layout
  • Algorithm for a smudge tool?
  • Why ng-show works with ng-repeat but ng-if doesn't? [duplicate]
  • Accessing IRQ description array within a module and displaying action names
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • How to set the response of a form post action to a iframe source?
  • Change div Background jquery
  • Qt: Run a script BEFORE make
  • reshape alternating columns in less time and using less memory