Adding drawn greyscale images on top of each other

1 回表示 (過去 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);
  1 件のコメント
Brian
Brian 2016 年 6 月 19 日
Thank you very much Guillaume.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by