Combining images to make a composite image
26 ビュー (過去 30 日間)
古いコメントを表示
I have created five heat maps using some custom colour maps. They look like this:
I would now like to combine them to make a composite image, ideally something that looks a little like the right hand side of this after all five images have been added:
Any help about how to get started on the problem would be most welcome.
Does this overlaying of images have a formal name? Searching online yielded no useful answers, maybe I'm using the wrong search terms.
2 件のコメント
Brian Cianciola
2018 年 8 月 15 日
編集済み: Chad Greene
2018 年 8 月 15 日
I think imfuse might be what you're looking for: https://www.mathworks.com/help/images/ref/imfuse.html
回答 (2 件)
Image Analyst
2018 年 8 月 16 日
Do they all have mutually exclusive pixels? That is no pixels are colored by more than one color map? If so, just convert to rgb using ind2rgb() and then add them all together.
2 件のコメント
Image Analyst
2018 年 8 月 22 日
You can still average them together, you'll just get blended/mixed colors.
DGM
2022 年 6 月 19 日
There are a number of ways to do this. As usual, I'm going to generalize a bit since I doubt OP is the one who will see this answer.
I'm going to make a few assumptions.
- The images are already given. I'm not going to consider possible methods to construct the final image directly from the original data.
- The images consist of colored content against a black background. Each image is represented by one hue.
- The non-black regions may overlap (stated).
- The images are all the same size.
The task is then one of image blending/compositing. As usual, I'm going to use some MIMT tools for certain tasks.
There are a number of simple blending approaches that can be used. Any blend mode with a neutral response at FG=0 might be something to consider. Consider the simple blend tests with the following step swatches:
%% simple color blending
fg = imread('fgswatch.png');
bg = imread('bgswatch.png');
%outpict = imblend(fg,bg,1,'screen');
%outpict = imblend(fg,bg,1,'addition');
%outpict = imblend(fg,bg,1,'lightenrgb');
outpict = imblend(fg,bg,1,'lighteny');
imshow(outpict)
The takeaway is that there are lots of ways to combine images, but each method has different properties that can be either advantageous or counterproductive depending on the context and expectations. These example modes are commutative, so the layer order has no influence over the degree to which a given layer is visible in the output. The mixing of the different colors may produce intermediate hues that would make reading the results ambiguous. The hard masking behavior of 'lighten y' (equivalent to Photoshop's 'lighter color') prevents color mixing, but it produces new edge features and obscures the underlying content.
We can apply these blending methods to a more complicated set of images. Consider the following set of four images:
% read all four demo images
% this could also just be done with a loop
B = mimread('Bdemo_*.png'); % read into a cell array
B = imstacker(B,'padding',0); % stack on dim4
% BLENDING METHODS
%outpict = mergedown(B,1,'screen');
%outpict = mergedown(B,1,'addition');
%outpict = mergedown(B,1,'lightenrgb');
%outpict = max(B,[],4); % same as lightenrgb for default parameters (not shown)
outpict = mergedown(B,1,'lighteny');
The differences may be subtle, but they may matter. Whether any of these is appropriate is a decision for the reader. I imagine that 'screen' and 'lightenrgb' are the most plausible, but needs differ.
Compositing or alpha blending might suggest another set of possible methods. Again, consider some swatch tests. If you were to do a simple scalar alpha blend, you'd get an overly dark image. This is simply average the images, and you'd be skewing the average by incorporating a bunch of black background content. The result would likely look dark and muted.
%% naive scalar opacity blend
% this is obviously garbage due to the black bg muting everything
fg = imread('fgswatch.png');
bg = imread('bgswatch.png');
% compose output image
outpict = imblend(fg,bg,0.5,'normal');
The contrast of the result can be stretched if desired, but there may not be much overhead before clipping occurs.
% compose output image
outpict = imblend(fg,bg,0.5,'normal');
outpict = im2uint8(mat2gray(outpict)); % adjust contrast
Lastly, a more complex approach can be taken. As the background is a solid color (black), it's possible to eliminate it. In that way, only the non-black content is being blended. In this example, MIMT color2alpha() is used to convert black to alpha content. The rest is simple composition as before. It should be noted that this method is not commutative. The layer order will directly influence which image content will be present in overlap regions.
% compose output image
fg = color2alpha(fg,[0 0 0]); % convert FG to an RGBA image
outpict = replacepixels(fg,bg,1); % this is an RGB image
As before, these methods can be applied to our four random test images:
% read all four demo images
B = mimread('Bdemo_*.png'); % read into a cell array
B = imstacker(B,'padding',0); % stack on dim4
% COMPOSITING METHODS
% naive uniform opacity blend (averaging)
%outpict = cast(mean(B,4),class(B));
% same, but with contrast adjustment
%outpict = imcast(mat2gray(mean(im2double(B),4)),class(B));
% composition of color content only
outpict = B(:,:,:,1); % base layer is the first frame
for f = 2:size(B,4)
fg = color2alpha(B(:,:,:,f),[0 0 0]); % this is an RGBA image
outpict = replacepixels(fg,outpict,1);
end
As mentioned before, most of these examples are based on MIMT tools. MIMT is available on the File Exchange.
This thread is a similar exploration of light-on-black multilayer blending/composition.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!