Effacer les filtres
Effacer les filtres

Adding drawn greyscale images on top of each other

3 vues (au cours des 30 derniers jours)
Brian
Brian le 17 Juin 2016
Commenté : Brian le 19 Juin 2016
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)

Réponse acceptée

Guillaume
Guillaume le 17 Juin 2016
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 commentaire
Brian
Brian le 19 Juin 2016
Thank you very much Guillaume.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by