Subplot Not showing Color - Montage with ROI's

6 次查看(过去 30 天)
Good afternoon,
I am fairly new to matlab and cannot figure out why my subplots are showing without color. I have tried color mapping or changing the settings of imshow but it still comes out in black and white. I am adding predefined ROI's (saved as variables) to a montage I created of every 10th (or 20th) frame in a sequence of IR data (.mat files). However, once I add the ROI's and crop the image, I cannot get it to populate in color. I attached the script I used to make the montage (that comes out in color) and the script below has to be where my issues are. If I try to change the color map I get an error that ignores it due to it being a "truecolor" image. I have tried to convert it and still get the same result.
Any help would be greatly appreciated!
Thank you,
Kegan
Code for adding the ROI's to the subplots.
clc;
% Load ROI information
load('roi_data.mat', 'rect_bckl', 'rect_worml1', 'rect_worml2', 'rect_worml3', 'rect_worml4');
% Specify the cropping dimensions
cropWidth = 0.4; % Width of the cropped region (40% of the original width)
cropHeight = 0.3; % Height of the cropped region (30% of the original height)
% Create a figure with subplots for the cropped images
figure;
numImages = size(montageMatrix, 4); % Number of images in the montage
numSubplots = min(numImages, 16); % Limit the number of subplots to 16 (4x4 grid)
for i = 1:numSubplots
% Get the current frame from the montageMatrix
frame = montageMatrix(:, :, :, i);
% Apply the ROIs on the current frame
frame = insertShape(frame, 'Rectangle', rect_bckl, 'LineWidth', 2, 'Color', 'red');
frame = insertShape(frame, 'Rectangle', rect_worml1, 'LineWidth', 2, 'Color', 'green');
frame = insertShape(frame, 'Rectangle', rect_worml2, 'LineWidth', 2, 'Color', 'blue');
frame = insertShape(frame, 'Rectangle', rect_worml3, 'LineWidth', 2, 'Color', 'yellow');
frame = insertShape(frame, 'Rectangle', rect_worml4, 'LineWidth', 2, 'Color', 'magenta');
% Crop the modified frame to keep only the center region
[imageHeight, imageWidth, ~] = size(frame);
cropX = round((imageWidth - cropWidth*imageWidth) / 2);
cropY = round((imageHeight - cropHeight*imageHeight) / 2);
croppedImage = frame(cropY:cropY+cropHeight*imageHeight-1, cropX:cropX+cropWidth*imageWidth-1, :);
% Display the cropped image in a subplot
subplot(4, 4, i);
imshow(croppedImage, 'InitialMagnification', 'fit');
title(['Frame ', num2str((i-1) * 10)]);
end

回答(1 个)

Mann Baidi
Mann Baidi 2023-8-29
编辑:Mann Baidi 2023-8-29
Hi Kegan,
I understand that you are facing issue in sub plotting the images in montage. I tried your code in my desktop,howerver I didn’t face any issue you encountered. I suggest you use the latest version of the MATLAB R2023a or check the images. I used the data of “peppers.png” image implemented your code.
y=load("peppers.mat");
% Create a blank montage matrix
montageMatrix = [];
montageMatrix=cat(4,montageMatrix,y.y);
montageMatrix=cat(4,montageMatrix,y.y);
montageMatrix=cat(4,montageMatrix,y.y);
The Image:

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by