concatenate multiple 2D arrays to a 3D array for an image file.
26 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I have an image file (.jpg) that I am trying to display on a graph side by side with the original of the image. After splitting the 3D color array into 3 2D arrays (RGB), I made an edit to the file, and tried to concatenate the layers back into a 3D matrix, but instead it's displaying the images side by side. How do I get the file to display the image with all 3 2D colormaps on top of each other instead of displaying them side by side?
[WhiteImg, colorMap] = imread('OrigImg.jpg');
Rlayer = ...
WhiteImg( :, :, 1);
Glayer = ...
WhiteImg( :, :, 2);
Blayer = ...
WhiteImg( :, :, 3);
% FIND WHITE PIXELS
logArray = ...
(Rlayer > 220) & (Glayer > 220) & (Blayer > 220);
intensity( :, :) = ...
uint8(mean([Rlayer, Glayer, Blayer], 3));
% INDEX NEW RGB LAYERS
Rnew = ...
intensity(:, :);
Gnew = ...
intensity(:, :);
Bnew = ...
intensity(:, :);
% SWAP WHITE FOR RED COLOR
Rnew(logArray) = 255;
Gnew(logArray) = 0;
Bnew(logArray) = 0;
% CONCAT
RedImg = ...
cat(3, Rnew, Gnew, Bnew);
% PLOTS
figure
blockPlots = subplot(1, 2, 1);
image(WhiteImg);
axis image
axis off
blockPlots = subplot(1, 2, 2);
image(RedImg);
axis image
axis off
0 Kommentare
Antworten (1)
Kevin Holly
am 31 Mär. 2022
Bearbeitet: Kevin Holly
am 31 Mär. 2022
[WhiteImg, colorMap] = imread('peppers.png');
Rlayer = ...
WhiteImg( :, :, 1);
Glayer = ...
WhiteImg( :, :, 2);
Blayer = ...
WhiteImg( :, :, 3);
% FIND WHITE PIXELS
logArray = ...
(Rlayer > 220) & (Glayer > 220) & (Blayer > 220);
intensity = uint8(mean(WhiteImg,3));
% INDEX NEW RGB LAYERS
Rnew = intensity;
Gnew = intensity;
Bnew = intensity;
% SWAP WHITE FOR RED COLOR
Rnew(logArray) = 255;
Gnew(logArray) = 0;
Bnew(logArray) = 0;
% CONCAT
RedImg = WhiteImg;
RedImg(:,:,1) = Rnew;
RedImg(:,:,2) = Gnew;
RedImg(:,:,3) = Bnew;
% PLOTS
figure
blockPlots = subplot(1, 2, 1);
image(WhiteImg);
axis image
axis off
blockPlots = subplot(1, 2, 2);
image(RedImg);
axis image
axis off
To make them closer together:
figure
imshowpair(WhiteImg,RedImg,"montage")
0 Kommentare
Siehe auch
Kategorien
Mehr zu Red finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!