Setting transparency for overlaying images
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi,
I am trying to overlay an image onto another. Currently I am using the following code however the problem is that, my transparency is always the same (0.75) for all images. However I need to have image specific transparency value. For example for that image, if I2 is more dominant then it should be seen dominant. But if I1 is dominant, then I2 should be seen more transparent. (I guess I need to set something like AlphaData but?)
I hope I could explain what I need. I will be very grateful if you can help me.
Regards, Amadeus
Here is the code:
for slicenum = 1 : size(nii.img,3)
I1 = nii.img(:,:,slicenum);
I2 = uint16(M(:,:,slicenum));
RGB2=ind2rgb(I2,colormap(hot));
figure,imshow(I1,[]);
hold on; h = imshow(RGB2);
alpha(0.75);
save_file_name = strcat(num2str(slicenum),'.jpg');
saveas(gcf,save_file_name);
pause(0.25)
end
댓글 수: 0
답변 (2개)
Image Analyst
2013년 2월 17일
See Steve's blog: http://blogs.mathworks.com/steve/2009/02/18/image-overlay-using-transparency/ Note how he changes the transparency as a function of location. Steve says:
"Using image data to control transparency
My second transparency example gets a bit more creative. I'll display an image that's a solid color, but I'll use another data set to vary the solid color image's transparency on a pixel-by-pixel basis. "
which sounds like it's exactly what you want to do.
댓글 수: 0
Walter Roberson
2013년 2월 17일
Calculate a variable, "thisalpha", as seems suitable, before doing the imshow(RGB2). Then,
imshow(RGB2, 'AlphaData', thisalpha);
And remember to destroy the figure afterwards or else your graphics will get slower and slower as you accumulate figures.
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!