multiple ROI in 2 images

8 views (last 30 days)
Meera chandran
Meera chandran on 30 Aug 2018
Commented: Meera chandran on 6 Sep 2018
I am trying to draw multiple ROI's in " different images ImgA & ImgB (which are the first 2 frames of a video). But, when I draw one ROI in imgA , it jumps to the step of identifying the salientpoints in the ROI and automatically the same ROI is displayed for imgB.
What change should I make here?
%%Load a video and draw ROI in the video/image frames
%%Input video file which needs to be stabilized.
filename = 'shaky_car.avi';
%Load the video using a video reader object.
videoFReader = vision.VideoFileReader(filename, ...
'ImageColorSpace', 'Intensity',...
'VideoOutputDataType', 'double');
%Create a video player object to play the video file
videoPlayer = vision.VideoPlayer;
while ~isDone(videoFReader)
frame = videoFReader();
videoPlayer(frame);
pause(0.01);
end
imgA = step(videoFReader);
imgB = step(videoFReader);
imshowpair(imgA,imgB,'montage');
objectRegion = round(getPosition(imrect));
objectImageA = insertShape(imgA,'Rectangle',objectRegion,'Color','red');
objectImageB = insertShape(imgB,'Rectangle',objectRegion,'Color','red');
figure;
imshowpair(objectImageA, objectImageB ,'montage');
title('Red box shows object region');
%Detect interest points in the object region.
pointsA = detectMinEigenFeatures(imgA,'ROI',objectRegion);
pointsB = detectMinEigenFeatures(imgB,'ROI',objectRegion);
%Display the detected points.
pointImageA = insertMarker(imgA,pointsA.Location,'+','Color','white');
pointImageB = insertMarker(imgB,pointsB.Location,'+','Color','white');
figure;
imshowpair(pointImageA,pointImageB,'montage');
title('Detected interest points');
release(videoFReader);
release(videoPlayer);
  4 Comments
Meera chandran
Meera chandran on 30 Aug 2018
What I wnat to achieve is,
1. Draw multiple ROI's in both Images.
2. Find the salient features in the ROI's drawn in both the Images.
Meera chandran
Meera chandran on 3 Sep 2018
Is this possible in MATLAB?

Sign in to comment.

Accepted Answer

Amal George M
Amal George M on 4 Sep 2018
Hi Meera,
The issue is caused since 'imshowpair' function creates only one axis. The same functionality can be achieved using 'subplot' to create a figure with two axis. When working with multiple axes objects, 'imrect' should be called using the required axis handle. To avoid the execution 'jump', you can use 'wait' function. It will pause the execution and allow you to modify the ROI after initially dragging the rectangle. Once satisfied with the dimensions of ROI, you can resume the execution by double-clicking inside the selected region.
Here is the modified custom code:
%%Load a video and draw ROI in the video/image frames
%%Input video file which needs to be stabilized.
filename = 'shaky_car.avi';
%Load the video using a video reader object.
videoFReader = vision.VideoFileReader(filename, ...
'ImageColorSpace', 'Intensity',...
'VideoOutputDataType', 'double');
%Create a video player object to play the video file
videoPlayer = vision.VideoPlayer;
while ~isDone(videoFReader)
frame = videoFReader();
videoPlayer(frame);
pause(0.01);
end
imgA = step(videoFReader);
imgB = step(videoFReader);
%%Code modified from this point
% imshowpair(imgA,imgB,'montage');
ax1 = subplot(1,2,1); %axishandle to first image is stored in ax1
imshow(imgA);
ax2 = subplot(1,2,2); %axishandle to second image is stored in ax2
imshow(imgB);
%imrect used with axis handle, wait function allows modification of ROI
objectRegionA = round(wait(imrect(ax1))); % result assigned to objectRegionA
objectRegionB = round(wait(imrect(ax2))); % result assigned to objectRegionB
objectImageA = insertShape(imgA,'Rectangle',objectRegionA,'Color','red'); % objectRegionA is used
objectImageB = insertShape(imgB,'Rectangle',objectRegionB,'Color','red'); % objectRegionB is used
figure;
imshowpair(objectImageA, objectImageB ,'montage');
title('Red box shows object region');
%Detect interest points in the object region.
pointsA = detectMinEigenFeatures(imgA,'ROI',objectRegionA); % objectRegionA is used
pointsB = detectMinEigenFeatures(imgB,'ROI',objectRegionB); % objectRegionB is used
%%Code modified till this point
%Display the detected points.
pointImageA = insertMarker(imgA,pointsA.Location,'+','Color','white');
pointImageB = insertMarker(imgB,pointsB.Location,'+','Color','white');
figure;
imshowpair(pointImageA,pointImageB,'montage');
title('Detected interest points');
release(videoFReader);
release(videoPlayer);
Note: For selecting multiple ROI in the same image, you can use a 'for' loop or any other iterative method.
Hope this helps.
  9 Comments
Amal George M
Amal George M on 5 Sep 2018
It is expected to take only the final ROI after modification. For creating multiple ROIs, 'imrect()' has to be used each time, with the corresponding image axis.
I am attaching the custom code as 'test2.m'. Use the 'Num' variable to modify the number of ROI's per image (line 25).
Meera chandran
Meera chandran on 6 Sep 2018
This is very much helpful..Thanks again for all your inputs :) You are a true MATLABian :D Have a nice Day!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!