concatenate multiple 2D arrays to a 3D array for an image file.

조회 수: 24 (최근 30일)
Lynne SOUTH
Lynne SOUTH 2022년 3월 31일
편집: Kevin Holly 2022년 3월 31일
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

답변 (1개)

Kevin Holly
Kevin Holly 2022년 3월 31일
편집: Kevin Holly 2022년 3월 31일
[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")

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by