Overlay transparent image on top of current figure
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I have been attempting (for far to long) to overlay a transparent image of the outline of footprints on top of a figure I have created. I've view previous posts on this topic but I can't seem to get it to work. Below is my simple code thus far, and the image I would like to use is attached. Can anybody please help?
clear all
clc
figure
LeftPosterior = rectangle('Position',[0 0 1 1],'FaceColor',[0 .5 .5]);
hold on
RightPosterior = rectangle('Position',[1 0 1 1],'FaceColor',[0 .8 .8]);
LeftAnterior = rectangle('Position',[0 1 1 1],'FaceColor',[0 .9 .9]);
RightAnterior = rectangle('Position',[1 1 1 1],'FaceColor',[0 .3 .3]);
axis([0 2 0 2])
axes('position',[0 0 1 1]);
[img, map, alphachannel] = imread('Footprint Pic.png');
image(img, 'AlphaData', alphachannel);
댓글 수: 0
채택된 답변
DGM
2023년 2월 8일
편집: DGM
2023년 2월 8일
Try this:
LeftPosterior = rectangle('Position',[0 0 1 1],'FaceColor',[0 .5 .5]);
hold on
RightPosterior = rectangle('Position',[1 0 1 1],'FaceColor',[0 .8 .8]);
LeftAnterior = rectangle('Position',[0 1 1 1],'FaceColor',[0 .9 .9]);
RightAnterior = rectangle('Position',[1 1 1 1],'FaceColor',[0 .3 .3]);
xrange = [0 2];
yrange = [0 2];
axis([xrange yrange])
[img, map, alphachannel] = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1289535/Footprint%20Pic.png');
image(xrange,yrange,img,'AlphaData',im2double(alphachannel));
% the origin of an image is the NW corner
% so you'll either have to flip the image and/or the y-axis
% to get things oriented the way you want
set(gca,'ydir','reverse');
Note that I flipped the y-axis. This is normally what image()/imshow() do when they're called first. If you want the origin to stay in the SW corner, you'll have to flip() the image. In general, you'd want to flip both the image and its alpha channel. In this specific case, there is actually no object content in img. The entire object content is in the alpha data, so you'd really only need to flip alpha.
댓글 수: 2
DGM
2023년 2월 8일
The images are just arrays, so:
alphachannel = flipud(alphachannel);
or
alphachannel = flip(alphachannel,1);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
