MATLAB:结合两个具有不同Alpha的灰度图像 [英] MATLAB: Combine Two Grayscale Images With Different Alpha

查看:159
本文介绍了MATLAB:结合两个具有不同Alpha的灰度图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始在MATLAB中编写程序,以动态覆盖具有相同alpha大小的两个相同大小的灰度图像.因此,两个图像都绘制在一个图中,并且在它们下面是一个滑块,使用该滑块可以将第二个图像的alpha从零增加到一个.因此,当移动滑块时,实际上可以看到两个图像融合在一起.假设滑块为0.3,则第二张图片的"AlphaData"设置为0.3,而第一张图片的"AlphaData"始终为1.在屏幕上,我现在看到一张图片,这是这两张图片的组合

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.

推荐答案

灰度图像只是数字数组.根据获取数据的方式,它可能是0〜1或1〜255.覆盖两个图像只是将数字相加.混合两个图像只是计算它们的加权和.

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)


要混合彩色图像,请在 MATLAB中查看我的答案:在RGB图像上应用透明蒙版并与另一个图像融合

这篇关于MATLAB:结合两个具有不同Alpha的灰度图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆