필터 지우기
필터 지우기

Adding drawn greyscale images on top of each other

조회 수: 3 (최근 30일)
Brian
Brian 2016년 6월 17일
댓글: Brian 2016년 6월 19일
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)

채택된 답변

Guillaume
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!

Translated by