Make only the highest values of grayscale image transparent
1 回表示 (過去 30 日間)
古いコメントを表示
For a grayscale image with values from 0 to 255, I would like to make only the highest values transparent, so the rest of the image will be black when I overlay it on another image
0 件のコメント
回答 (2 件)
Walter Roberson
2024 年 6 月 10 日
編集済み: Walter Roberson
2024 年 6 月 10 日
image(BackgroundImage);
imageMax = max(YourGrayscaleImage(:));
alphaMask = double(YourGraycaleImage == imageMax);
hold on
image(YourGrayscaleImage, 'alphadata', alphaMask);
hold off
colormap(gray(256))
0 件のコメント
DGM
2024 年 6 月 11 日
I'm going to assume that the goal is to combine two images of the same page geometry and then save the result. If the end goal is to have a composite image to keep, then don't rely on in-figure composition and screenshots. Just compose the image.
Generate a mask by some means -- for example, logical thresholding:
% two images of the same class, depth, and page geometry
BG = imread('cameraman.tif'); % uint8
FG = fliplr(BG); % a second test image
% select everything lighter than 65% gray
mask = FG > (255*0.65);
% assemble the output using logical indexing
outpict = BG;
outpict(mask) = FG(mask);
imshow(outpict,'border','tight')
Of course that's not robust at all. If you want to deal with soft or graduated masks, color images, or mixed numeric classes, then there are plenty of examples:
If your goal is something else, then you'll have to elaborate.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!