Image overlay and colormaps

조회 수: 6 (최근 30일)
Zacharias Kandylakis
Zacharias Kandylakis 2014년 11월 19일
답변: Prateekshya 2024년 10월 11일
I am using the sc() function to overlay two images
1. a greyscale background
2. an image of pH levels with a custom colormap
( range of values is appr. 2.9 to 4 )
The visual result is as intended, however when I show the colorbar() I get the grayscale bar. I need to show the custom map colorbar. It is also important that the values are not scaled in 0-1 but remain at 2.9-4.
P.S. I have tried using built in cmaps such as 'prob','hot' and I have the same problem.

답변 (1개)

Prateekshya
Prateekshya 2024년 10월 11일
Hello Zacharias,
To overlay two images in MATLAB and display a custom colormap for the second image with its own colorbar, you can use the following approach. The idea is to ensure that the colormap and color limits are set correctly for the pH image, and the colorbar reflects this custom colormap instead of the grayscale one. You can follow these steps:
  • Display the Grayscale Background: Use the imshow function to display the grayscale image.
  • Overlay the pH Image: Use the hold on command to overlay the second image with a custom colormap.
  • Set the Colormap and Color Limits for the pH Image: Adjust the colormap and color limits to reflect the actual range of the pH image.
  • Display the Colorbar: Ensure the colorbar corresponds to the pH image by setting the correct limits and colormap.
Here is an example code snippet:
% Load or create your images
grayImage = imread('grayscale_image.png'); % Replace with your grayscale image
pHImage = imread('pH_image.png'); % Replace with your pH level image
% Display the grayscale image
imshow(grayImage, []);
hold on;
% Display the pH image with transparency
h = imshow(pHImage, []);
set(h, 'AlphaData', 0.5); % Adjust transparency as needed
% Define the custom colormap for the pH image
customCMap = jet(256); % Example: use 'jet' colormap, or define your own
% Set the colormap and color limits for the pH image
colormap(customCMap);
caxis([2.9 4]); % Set color limits to match pH value range
% Display the colorbar
colorbar;
% Ensure the colorbar reflects the pH image
cb = colorbar;
cb.Label.String = 'pH Level';
I hope this helps!

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by