are we able to getposition while vision.VideoPlayer is running? - matlab

In Matlab, I need to manually select object from vision.VideoPlayer directly while it is running. instead of show frame and then use figure; imshow(frame); objectRegion=round(getPosition(imrect))
are we able to do this?

No, unfortunately, you cannot. You would have to use imshow to display the image, to be able to use imrect.

Related

Why does Matlab set the background white when saving a scope printed to figure?

I want to programmatically 'Print to figure' a Simulink scope and save the resulting figure to a folder.
Consider following Simulink model and select the scope:
I run following code (inspired by this question):
scopeName=get_param(gcb,'Name');
hs=findall(0,'Name',scopeName);
hf=figure(1);
hp=findobj(hs.UserData.Parent,'Tag','VisualizationPanel');
copyobj(hp,hf)
filename='test.tiff';
print('-dtiff',filename);
Although both the scope and the figure have a black background
the saved file has a white background
Is there something wrong with the print command or with something else?
By default, MATLAB inverts the background colors when printing to a figure. To get around this, you can set the InvertHardCopy to 'off'
set(gcf, 'InvertHardCopy', 'off')
Doing this (as opposed to using getframe) results in a much higher resolution image as getframe simply saves the figure at screen resolution (72dpi).
Another option is to use export_fig from the MATLAB file exchange to save the figure which will more reliably reproduce the image that is on your screen.
You can get the same view as you see:
img = getframe(gcf);
imwrite(img.cdata,'test.tiff');

imshowpair function

Is it possible to use imshowpair function in MATLAB to display images next to each other instead of over one another?
So far I have:
figure;
imshowpair(imgA, imgB, 'diff');
I have about 100 images I would like to display. Is it possible?
Indeed it is possible.
imshowpair(im1, im2, 'montage')
It only displays 2 images, though. If you need to display many images of the same size use the montage function.
you also can use
newImg = cat(2,img1,img2);

Cutting part of image and saving to file in MATLAB

Lets assume i have image 'image.jpg'.
I want to choose part of it with imrect function, and save to new file 'newimg.jpg'.
Do you have any idea how to implement in a simple way?
Thanks.
Use the imcrop function to cut out the region, and then imwrite to save it into a separate image.

how to stop Matlab figure from maximizing?

I want to disable the Maximize option of Matlab figure.
There's a figure property you need to change for that:
set(fHandle,'Resize','off');
The MATLAB File Exchange has WindowAPI, which does exactly what you're looking for.
You can crop the complete window border by:
WindowAPI(gcf, 'Clip', true);

Selecting a ROI manually in Matlab

I'm trying to select a user-defined area and fill with 1s, preferably with mouse input. Any suggestion how? Thanks.
The command
roipoly
does exactly what you're looking for.
You'll need the Image Processing Toolbox to use roipoly as Georg suggested.
If you don't have that, you could try creating a rubber band box using
rbbox
There's a good example in the help. You might need to fiddle with units depending on how you're displaying your data. Remember to click and hold, drag and release..
h=impoly;
This code helps you to select a closed polygon of the image.