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 comentarios

Image Analyst
Image Analyst el 30 de Ag. de 2018
What line of code lets you draw the ROI, and what line of code (step) does it jump to after you draw it?
Meera chandran
Meera chandran el 30 de Ag. de 2018
Hi,
the code which I use for drwaing ROI is :
objectRegion = round(getPosition(imrect));
objectImageA = insertShape(imgA,'Rectangle',objectRegion,'Color','red');
objectImageB = insertShape(imgB,'Rectangle',objectRegion,'Color','red');
Once I draw the ROI in ImgA, it jumps to showing the feature points in both Images(ImgA & ImgB , where I havent drawn the ROI in ImgB).
Meera chandran
Meera chandran el 30 de Ag. de 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 el 3 de Sept. de 2018
Is this possible in MATLAB?

Iniciar sesión para comentar.

 Respuesta aceptada

Amal George M
Amal George M el 4 de Sept. de 2018

0 votos

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 comentarios

Meera chandran
Meera chandran el 4 de Sept. de 2018
Hi Amal, Thanks for your comment. I tried running this but its not working . Is this working for you?
objectRegionA = round(wait(imrect(ax1)));
This is not creating an 'objectRegionA', I had to use
objectRegionA = round(getPosition(imrect(ax1))); %works
wait(objectRegionA); %throws error
Undefined function 'wait' for input arguments of type 'double'.
Amal George M
Amal George M el 5 de Sept. de 2018
As per my understanding, you are unable to execute the code which I shared. Can you mention the exact difficulty that you are facing while running the code? Attach any error messages or screenshots for better understanding and specify the MATLAB Version that is being used.
Also, mention the format 'objectRegionA' needs to be in. The current datatype format is such that extracting points using 'detectMinEigenFeatures' is possible. This is similar to the datatype format 'objectRegion' present in your code, which is 1x4 double representing [x y width height] of the ROI.
' wait() ' only takes ROI objects as input. ROI object is created using ' imrect() '. Therefore if you modify the code to
objectRegionA = round(getPosition(imrect(ax1)));
wait(objectRegionA);
It will result in an error since 'objectRegionA' is of double datatype.
Meera chandran
Meera chandran el 5 de Sept. de 2018
I am attaching the screenshot of Figure, in which ROI has to be drawn. I am able to draw the ROI only in first frame as shown.
And I am getting the following error:
Error using roiParseInputs (line 74) HPARENT must be a valid graphics handle.
Error in imrect>imrectAPI (line 182) [commonArgs,specificArgs] = roiParseInputs(0,2,varargin,mfilename,{'DrawAPI'});
Error in imrect (line 82) [h_group,draw_api] = imrectAPI(varargin{:});
Error in Untitled1 (line 25) objectRegionB = round(wait(imrect(ax2))); % result assigned to objectRegionB
What I am trying to achieve is, draw multiple ROI's in first 2 frames and extract the feature points in those selected[ROI] areas.
  • Matlab version: MATLABR 2018a*
update: I was able to draw multiple ROI's in the frames, but only the last drawn ROI is saved and only its feature points are extracted.
Amal George M
Amal George M el 5 de Sept. de 2018
The code was only intended to take a single ROI per image.
The possible reason for this error could be the presence of an open figure prior to the execution of the code. To check this possibility, add this code before the line "ax1 = subplot(1,2,1);" (line 18).
figure % to create a new figure window
and
close all;
to the beginning of the code.
I am attaching the modified code as a "test.m" file.
Meera chandran
Meera chandran el 5 de Sept. de 2018
Hi Amal, I run the 'test.m' file but its giving the same result as the earlier one. I cant draw the ROI in second frame.
Amal George M
Amal George M el 5 de Sept. de 2018
Editada: Amal George M el 5 de Sept. de 2018
Was the error same as mentioned before?
Just to clarify; To resume the execution after dragging the first ROI in image 1, you have to double click inside the selected region. I am assuming you are getting the error after double clicking inside the region.
I am asking this, since I could reproduce the error only by deliberately modifying 'ax2' handle variable after the line "ax2 = subplot(1,2,2);". Are there any other Matlab programs running, which could possibly modify the variable?
Please reply if the problem persists. So that I can investigate the issue further and work with you to resolve it.
Meera chandran
Meera chandran el 5 de Sept. de 2018
I was not double clicking the ROI drawn ..Now i can draw ROI in both frames. Thanks a lot for your help :)
But now, I can draw multiple ROI in these 2 frames, but only the last drawn ROI in each frame is only used for detecting features. How can get all the ROI feature points in these 2 images? Any thoughts?
Amal George M
Amal George M el 5 de Sept. de 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 el 6 de Sept. de 2018
This is very much helpful..Thanks again for all your inputs :) You are a true MATLABian :D Have a nice Day!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 30 de Ag. de 2018

Comentada:

el 6 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by