multiple ROI in 2 images

3 次查看(过去 30 天)
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 个评论
Meera chandran
Meera chandran 2018-8-30
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 2018-9-3
Is this possible in MATLAB?

请先登录,再进行评论。

采纳的回答

Amal George M
Amal George M 2018-9-4
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 个评论
Amal George M
Amal George M 2018-9-5
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 2018-9-6
This is very much helpful..Thanks again for all your inputs :) You are a true MATLABian :D Have a nice Day!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Computer Vision with Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by