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

25 ビュー (過去 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 Center および File ExchangeRed についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by