MATLAB Answers

Embed cropped image within original image using 'drawpoint'

조회 수: 4(최근 30일)
Luke G.
Luke G. 2021년 3월 9일
댓글: Luke G. 2021년 3월 30일
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;

채택된 답변

Tarunbir Gambhir
Tarunbir Gambhir 2021년 3월 23일
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
Luke G.
Luke G. 2021년 3월 30일
Tarunbir, thanks for taking the time to answer. Such a simple mistake! Cheers

댓글을 달려면 로그인하십시오.

추가 답변(0개)

Community Treasure Hunt

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

Start Hunting!

Translated by