multiple ROI in 2 images
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Meera chandran
am 30 Aug. 2018
Kommentiert: Meera chandran
am 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 Kommentare
Akzeptierte Antwort
Amal George M
am 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 Kommentare
Amal George M
am 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).
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Computer Vision with Simulink finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!