How to combine multiple true color images into a composite image?
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dinuka Kankanige
le 14 Avr 2023
Commenté : Dinuka Kankanige
le 18 Avr 2023
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 commentaires
DGM
le 14 Avr 2023
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?
Réponse acceptée
DGM
le 14 Avr 2023
Modifié(e) : DGM
le 14 Avr 2023
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 commentaires
DGM
le 15 Avr 2023
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.
Plus de réponses (1)
Image Analyst
le 15 Avr 2023
See the attached published article on how to combine various wavelength bands into a visible RGB image.
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!