How can i create a black and white mask for my thermo image? When i run this code,my mask is just a green block but it should be white and black. Everything under 10 is white

2 次查看(过去 30 天)
% displayCSVImage.m - Script to load and display a CSV image based on picture number
% Specify the path to the folder containing your CSV files
folderPath = '/Users/jchedjou/Desktop/THERMO';
% Specify the picture number you want to display
pictureNumber = '001'; % Change this number to select a different picture
% Construct the filename of the CSV file you want to display
% Format: 'Image099_XXX.csv' where XXX is the picture number
fileName = sprintf('Image099_%s.csv', pictureNumber);
% Full path to the CSV file
fullFilePath = fullfile(folderPath, fileName);
% Check if the file exists
if ~isfile(fullFilePath)
fprintf('File does not exist: %s\n', fullFilePath);
return;
end
% Use your importfile function to load the data
data = importfile(fullFilePath, [18, Inf]); % Adjust [18, Inf] as needed
% Create a binary mask where values under 10 are set to 1 (white) and values 10 or above are set to 0 (black)
handMask = double(data < 10);
% Display the original image, the black and white mask, and the mask overlaid on the image
figure;
% Plot the original image
subplot(1, 3, 1);
imagesc(data);
colorbar;
axis equal;
title(['Original Image: ', fileName]);
% Plot the black and white mask
subplot(1, 3, 2);
imagesc(handMask);
colormap(gray); % Set colormap to grayscale for binary image
axis equal;
title(['Black and White Mask: ', fileName]);
% Plot the mask overlaid on the original image
subplot(1, 3, 3);
imagesc(data);
hold on;
h = imagesc(handMask);
set(h, 'AlphaData', handMask); % Use the binary mask as AlphaData
colormap(jet); % Adjust the colormap if necessary
colorbar;
axis equal;
title(['Mask Overlaid on Image: ', fileName]);

回答(1 个)

Cris LaPierre
Cris LaPierre 2024-2-6
You are changing the colormap for the entire figure. You need to change it for just the specific axis. Try updating the code in your second plot to this
colormap(gca,gray);

Community Treasure Hunt

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

Start Hunting!

Translated by