How to combine multiple true color images into a composite image?

13 ビュー (過去 30 日間)
Dinuka Kankanige
Dinuka Kankanige 2023 年 4 月 14 日
コメント済み: Dinuka Kankanige 2023 年 4 月 18 日
I'm having 16 true color images each representing different regions of a continent. I need to combine all 16 images and get the composite true color image of the continent. Could anyone please guide me through this? Sample images (.png) are attached herewith for reference in case needed. Each having size 630×840×3 and data type uint8. Appreciate your suggestions.
(R2020b)
  2 件のコメント
DGM
DGM 2023 年 4 月 14 日
This would be better done by working with the original data instead of screenshots. Do you have the original data or the code that generated the images?
Dinuka Kankanige
Dinuka Kankanige 2023 年 4 月 15 日
@DGM Thanks a lot for the answer below!
By the way, I'm attaching the original data herewith. If you could look into fixing the differently colored segments using these data, could you please comment.
(Original data contains (1) CMG gridded data & (2) uint8 pixel data for images corresponding to CMG gridded data)

サインインしてコメントする。

採用された回答

DGM
DGM 2023 年 4 月 14 日
編集済み: DGM 2023 年 4 月 14 日
If you're stuck doing this by image processing, here's one way.
basepath = '16 truecolor png files'; % the folder where the files are
SD = dir(fullfile(basepath,'*.png')); % get all the file names
bgcolor = [61 38 168]; % the nominal background color (uint8-scale)
for k = 1:numel(SD)
% read the file
thisfname = fullfile(basepath,SD(k).name);
thispict = imread(thisfname);
% construct the output one frame at a time
if k == 1
outpict = thispict;
else
mask = all(thispict ~= permute(bgcolor,[1 3 2]),3);
mask = repmat(mask,[1 1 3]);
outpict(mask) = thispict(mask);
end
end
imshow(outpict)
You might ask why some of the peripheral segments are colored differently. That's simply because that's the way they were plotted. They probably are not mapped consistently; rather, each segment is likely colormapped with respect to its local extrema. If you want to fix these segments, you need the data or the code which generated the plots.
  3 件のコメント
DGM
DGM 2023 年 4 月 15 日
Start by compositing the data into a single array containing all segments.
basepath = 'original data/1_CMG 0.01 deg'; % the folder where the files are
SD = dir(fullfile(basepath,'firemask_resampled_*.mat')); % get all the file names
outpict = [];
for k = 1:numel(SD)
% read the file
thisfname = fullfile(basepath,SD(k).name);
S = load(thisfname);
thispict = S.FireMask_0dot01degree_AU;
% composite the data one frame at a time
if k == 1
alldata = thispict;
else
mask = thispict ~= 0;
alldata(mask) = thispict(mask);
end
end
At this point, you'll have one 3000x5000 floating point array with all the data in it. Since they're all together, if you feed it to imagesc() or imshow(), the color scaling corresponds to the global extrema across all segments. When the segments were displayed one at a time, the scaling corresponded to the extrema of each segment individually.
% display the image in pseudocolor
% using a specified colormap
CT = parula(256); % some map
imshow(alldata,[]) % mapping corresponds to data extrema
colormap(CT)
Alternatively, if you want your output to be an RGB image instead of merely an ephemeral display on screen, you can use the attached tools to convert it to one. This should basically emulate what imshow()/imagesc() do when they apply the same colormap.
% convert the data to a pseudocolor image directly
% this can be saved/edited/displayed as needed
% without losing resolution or having other problems
% associated with doing figure capture
zrange = imrange(alldata);
outpict = gray2pcolor(alldata,CT,zrange,'cdscale');
imwrite(outpict,'mypseudocolorimage.png') % can be written directly
imshow(outpict) % or displayed
That'll keep the full resolution and aspect ratio.
Dinuka Kankanige
Dinuka Kankanige 2023 年 4 月 15 日
@DGM Thank you again. This is indeed helpful!

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2023 年 4 月 15 日
See the attached published article on how to combine various wavelength bands into a visible RGB image.

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by