Embed cropped image within original image using 'drawpoint'

1 vue (au cours des 30 derniers jours)
Luke G.
Luke G. le 9 Mar 2021
Commenté : Luke G. le 30 Mar 2021
I want to display a scaled up user-defined region of interest (ROI) within the original image. The issue:
The code:
clc, clear, close all
% select zoomed in ROI
firstFrame = imread('tiger_test.jpg');
imshow(firstFrame);
title('Select zoom region:','FontSize',16);
zoom = drawrectangle('Color',[1 1 0]);
zoomRegion = zoom.Position;
close all
% decide where to put it
imshow(firstFrame);
title('Click where (LH corner) to put it:','FontSize',16);
poop = drawpoint;
x_inset = round(poop.Position(1));
y_inset = round(poop.Position(2));
close all
% test it: overlay the two images
cropped = imcrop(firstFrame,zoomRegion);
newFrame = imresize(cropped,2); % scale up by 1.5x
newFrame_dim = size(newFrame);
x_w = newFrame_dim(1);
y_w = newFrame_dim(2);
firstFrame(x_inset:(x_inset+x_w-1),y_inset:(y_inset+y_w-1),:) = newFrame;
figure
imshow(firstFrame);
drawnow;

Réponse acceptée

Tarunbir Gambhir
Tarunbir Gambhir le 23 Mar 2021
From the code that you have shared, I see the issue with the use of variables "x_inset" and "y_inset". When using these indices to slice the image matrix "firstFrame" at the end, the first index should be for the y-coordinate as for a matrix it refers to the rows. Similarly, the second index should be for the x-coordinate refering the columns.
A simple fix to your code can be the following:
x_inset = round(poop.Position(2));
y_inset = round(poop.Position(1));
Update these lines of your code. If possible you can change the variable name accordingly so it is easier to reference it in the future.
  1 commentaire
Luke G.
Luke G. le 30 Mar 2021
Tarunbir, thanks for taking the time to answer. Such a simple mistake! Cheers

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by