Create transparent overlay imagesc for certain values
Show older comments
I have an elevation tif (4669x6692 single) (First image) and I performed a wavelet transform on it (Second image).
Now I want to overlay the wavelet transform data over the original elevation tif but only showing data within a certain threshold, so basically making all the blue data in the wavelet transparent/NaN/.... I tried different methods but overall, the colormap keeps plotting the full extent of the data. How can I create an overlay so that it only plots the data within a threshold (currently between 2 - 4)? The intented outcome is the third image.
for j = 1:numel(thresholdPercentiles)
threshold = thresholdValues(j);
% Set coefficients below the threshold to zero
waveletCoefficients(waveletCoefficients < threshold) = 0;
% Create a mask for values between 2 and 4
mask = (waveletCoefficients >= 2) & (waveletCoefficients <= 4);
% Create a masked version of the data with NaN for non-masked values
maskedData = data;
maskedData(~mask) = NaN;
% Display the masked values with transparency
subplot(3, 2, j+1);
imagesc(maskedData);
colormap('jet');
colorbar;
title(sprintf('Threshold: %dth percentile', thresholdPercentiles(j)));
% Apply transparency to the unwanted data (values other than 2-4)
alphaMask = double(~mask);
alphaMask(alphaMask == 1) = 0; % Set non-masked values to transparent
% Update the colormap with transparency (alpha channel)
cmap = colormap('jet');
cmap = [cmap(:, 1:3), alphaMask]; % Update the colormap
% Apply the updated colormap with transparency
colormap(cmap);
colorbar;
end



Accepted Answer
More Answers (1)
Image Analyst
on 2 Jun 2023
0 votes
You can use labeloverlay
Categories
Find more on Image Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!