Adding drawn greyscale images on top of each other
1 次查看(过去 30 天)
显示 更早的评论
Hi
I would like to draw a figure -> save it as an greyscale image and put it on top of another image. When I plot combined image there is a white frame around the drawn image. When I run the following example I get the shown image. When i prope the value in the white frame is shows the correct greyscale value.
Does anyone know what I am doing wrong and know how to fix it?
(Ps. the reason that I do not just draw directly on the first image is because I would like to do transformations of the drawn image using the tools in matlab before it is added on top of the other.)
bg = randn(700,1000);
length = 300; %[pixels]
width = 400; %[pixels]
[sizey,sizex] = size(bg);
xstart = (sizex-length)/2;
ystart = (sizey-width)/2;
xcor = [xstart, xstart, xstart+length, xstart+length, xstart];
ycor = [ystart, ystart+width, ystart+width, ystart, ystart];
figure('Position', [100, 100, length, width]); %Make figure in "true size"
set(gca,'color','none')
patch(xcor, ycor,'green')
axis off
axis image
F = getframe(gcf);
[specimen,~] = frame2im(F);
specimen = im2double(rgb2gray(specimen)); % image of the drawn rectangle
imshow(specimen)
bg(1:400,1:300) = specimen; % putting the image on top of each other.
imshow(bg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/154093/image.png)
0 个评论
采纳的回答
Guillaume
2016-6-17
The grey frame is because your axes does not occupy the whole figure, by default matlab leaves some margin around axes.
Set the position of the axes to occupy the whole figure and all will be well:
figure('Position', [100, 100, length, width]); %Make figure in "true size"
set(gca,'color','none');
patch(xcor, ycor,'green');
axis off;
axis image;
set(gca, 'Position', [0 0 1 1]);
F = getframe(gcf);
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!