Create transparent overlay imagesc for certain values
Mostrar comentarios más antiguos
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



Respuesta aceptada
Más respuestas (1)
Image Analyst
el 2 de Jun. de 2023
0 votos
You can use labeloverlay
Categorías
Más información sobre Image Analysis en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!