matlab: using the GPU for saving an image off a figure - matlab

I use matlab to render a complex mesh (using trimesh, material, camlight, view...) and need not display it to the user, just to get the rendered image. This is discussed in another question.
Using any of the suggested solutions (save-as image, saving into a video object, and using undocumented hardcopy) is very slow (~1sec), especially compared to rendering the plot itself, including painting on the screen takes less than 0.5sec.
I believe it is caused by hardcopy method not to utilize the GPU, while rendering the original plot for display do use the GPU; using GPU-Z monitor software I see the GPU working during ploting but not during hardcopy.
The figure use 'opengl' as renderer, but hardcopy, which is the underlying implementation of all the suggested methods, don't seem to respect this...
Any suggestion on how to configure it to use the GPU?
EDITED: following this thread I've moved to use the following, but GPU usage is still a flatliner.
cdata=hardcopy(f, '-Dopengl', '-r0')

Related

impoly become slow in MATLAB deployed standalone application

I'm building a standalone guide application which uses impoly inside.
When I drag the vertices of polygon created using impoly or drag the polygon itself, there's noticeable delay for actions, this doesn't happen in the MATLAB script file.
Even a simple script like the code below will create the delay after being converted to executable.
figure, imshow('peppers.png')
h = impoly(gca, []);
What is causing the delay here, and how can I solve this?
I know that using self defined drawing functions and windowbutton functions is faster but I don't want to lose the ease of using an impoly object because it's handled by internal codes.
The compiler version is R2011a.
Updates:
Not only impoly becomes slow when deployed. All rendering of graphic objects become slow. Pan tool and zoom tools have delays as well.
The solution is using uiwait to block the execution before exit. But I don't know why that solves the problem.

3D volume rendering in MATLAB

I started with the vol3d function from MATLAB file exchange for the 3D display part but its slowing down the entire application.
I am working on a MATLAB based GUI. Need to display a volume of size 512X512X512, single precision. The display has 4 different views of the volume. 3 standard orthogonal views and the 4th view is the 3D rendered isometric view.
With vol3D, The display is looking fine but its causing the GUI little lagging and slow. If I remove the vol3d function, the GUI works fine, faster.
I am new in the field of 3D volume rendering. What are the alternatives to this volume rendering in MATLAB. Is there any way to call some C-subroutine using mex, do the calculation in C and display in MATLAB. I have a good GPU(GeForce gtx titan x, 12 gb) but I am afraid I am not utilizing it well for the volume rendering thing.
Any suggestions are welcome.
thanx for reading :)

How to plot vector (not rastered as pixels) graphics in opencv

Being used to Matlab and its great capabilities of drawing vector graphics, I am looking for something similar in OpenCV. OpenCV drawing functions seem to raster the lines or points at pixel level. Currently, I am dumping the data into text, copy-paste to Matlab and doing all the plots. I also thought about using Matlab engine to pass it the parameters and running plots, but it seems to be too much mess for simple debug operation.
I want to be able to do the following:
Zoom in, out of the image
Draw a line/point which is re-rastered each time I do zoom, like in Matlab.
Currently, I found image watch plugin to take care of zooming, but it does not help with the second part.
Any idea?
OpenCV has a lot of capabilities to process an image but only minimal ones for displaying the result. It has nothing that can display vector graphics like Matlab. When I need to see polygons on image (or just polygons) I am dumping them to file and using third party viewer (usually Giv viewer).

Matlab face alignment code

I am attempting to do some face recognition and hallucination experiments and in order to get the best results, I first need to ensure all the facial images are aligned. I am using several thousand images for experimenting.
I have been scouring the Internet for past few days and have found many different programs which claim to do so, however due to Matlabs poor backwards compatibility, many of the programs no longer work. I have tried several different programs which don't run as they are calling onto Matlab functions which have since been removed.
The closest I found was using the SIFT algorithm, code found here
http://people.csail.mit.edu/celiu/ECCV2008/
Which does help align the images, but unfortunately it also downsamples the image, so the result ends up quite blurry looking which would have a negative effect on any experiments I ran.
Does anyone have any Matlab code samples or be able to point me in the right direction to code that actually aligns faces in a database.
Any help would be much appreciated.
You can find this recent work on Face Detection, Pose Estimation and Landmark Localization in the Wild. It has a working Matlab implementation and it is quite a good method.
Once you identify keypoints on all your faces you can morph them into a single reference and work from there.
The easiest way it with PCA and the eigen vector. To found X and Y most representative data. So you'll get the direction of the face.
You can found explication in this document : PCA Aligment
Do you need to detect the faces first, or are they already cropped? If you need to detect the faces, you can use vision.CascadeObjectDetector object in the Computer Vision System Toolbox.
To align the faces you can try the imregister function in the Image Processing Toolbox. Alternatively, you can use a feature-based approach. The Computer Vision System Toolbox includes a number of interest point detectors, feature descriptors, and a matchFeatures function to match the descriptors between a pair of images. You can then use the estimateGeometricTransform function to estimate an affine or even a projective transformation between two images. See this example for details.

comparing a known object in different pictures to find position and orientation error?

I am new to this place. I am doing a project where i use X ray images with known object dimensions. During my scan i want to compare the images with respect to first image to measure the position and orientation errors during my manipulator movement.
1) I use a known object next to my measuring object to check the errors.
How can i compare two or different images with same known objects?
2) I am planning to use matlab toolbox for the further processing. Is it possible to do in matlab? If so can somebody help
3) Is it possible to use POSIT algorithm to just find these errors?
You're asking a fairly complex question, without adding a lot of detail. We can only help you properly if you provide a bit more context, perhaps some examples of images.
By the sound of it: you should use the image processing toolbox.
If you have multiple images of test objects with known objects beside it, it is easiest to use normxcorr2 and friends (see this page for a worked-out example).
If you have a large amount of pictures of the same scene, possibly with rotations, scaling, optical distortions, etc. from image to image, and you still want a sub-pixel accurate estimation of your object's position, perhaps image registration is the better way to go.
But again: you should provide more detail. Only then can we give you a better, less generic answer.