Wednesday, October 19, 2016

Uploading a technical report to arXiv

Recently, I had to upload a technical report to arXiv. Their system requires that the LaTeX source has to be included. Actually, for computer vision and graphics paper where lots of images are included in the paper, uploading the LaTeX source is not straightforward. 

The scenario I encounter is that I have a complex LaTeX file with a bunch of figures. Each figure is made by a few minipages that include tens of images. As the arXiv system does not allow multiple files upload at a time, and due to the complicated file organization in my figure folder, it does not make sense to upload all the figure images. 

My solution is to split all the figures and tables into a single pdf file, and then modify the existing LaTeX file to include figures from the pdf instead. The steps are as follows. 

1. Include
\usepackage[active,tightpage,floats]{preview}
to the original LaTeX and compile. All floats (including captions) will be saved into a single pdf. Let's say we name it figures.pdf. 

2. Fork the original LaTeX to a new file, e.g., name arxiv.tex. In this file, all figures that has minipages and includegraphics are replaced with the code like this:

\begin{figure}
    \centering
    \includegraphics[page=X]{figures.pdf}
    \caption{}
    \label{fig:abc}
\end{figure}
where X is the page number to include. 

Note that to maintain correct cross-reference, figure caption and label has to be declared. Since the caption is already included in figures.pdf, we simply put an empty caption here. Remember to include
\usepackage{caption}
\captionsetup[figure]{labelformat=empty}
at the beginning to disable the caption numbering. This assumes that all figures are managed this way so disabling the caption numbering does not affect other figures. 

If compression is needed, one can compress the figures.pdf accordingly. 

3. Finally, simply upload arxiv.tex, arxiv.bbl, and figures.pdf, and other necessary class and style files if necessary. Note that arXiv does not compile BibTex (.bib) file automatically. One has to compile it and only upload the .bbl file. Uploading .bib file does not work. 

P.S. Do not treat your original paper as a figure and create arxiv.tex that looks like this:
\documentclass[a4paper]{article}
\usepackage{hyperref}
\hypersetup{
  pdfinfo={
    Title={},
    Author={},
    Subject={},
    Keywords={}
  }
}
\usepackage{pdfpages}

\begin{document}
\includepdf[pages=1-last]{original.pdf}
\end{document}

This can bypass the submission system, but the arXiv admin will hold your submission until you contact them. :) 

Thursday, April 21, 2016

Insect 3D models

I just came across some great free 3D models of insects on the web. In Wavefront OBJ format. Download them at http://zerokobo.web.fc2.com

Thursday, March 24, 2016

How to add narration for a PowerPoint video

It has been increasingly popular to have a video as supplementary material for paper submission. The video, usually less than 5 minutes, explains the key ideas of the paper in an intuitive way.
In addition, the video is narrated for viewers to catch the ideas quickly.

In this post, I'm describing how I made such a video using free and open-source tools. The only exception is Microsoft PowerPoint, which I used to make the presentation slides which are then exported to the video.

The workflow is as follows:
1. Make the slides.
2. Record the timing and narration for the slides. Suppose that both the slides and the narration are done by you in PowerPoint, then this is simple. Just go to SlideShow tab -> Record Slide Show.

The situation becomes more complex if you are not a native speaker and need someone else to help with the narration. It means, we need to merge an audio file to our existing video.

The workflow becomes:
1. Make the slides.
2. Wait for someone to make the narration audio. Take the audio file (e.g., mp3 format).
3. Segment the narration audio into parts.
4. Record the timing of the slides based on the length of each narration part. Export the slides to video.
5. Merge the audio parts to the video.

I did the steps above using Audacity and Blender.

In step 3, it is best to cut the audio into parts, one for each slide. This can be done easily in Audacity. Open the audio in Audacity, select the narration for each slide, press Ctrl + B to label it (i.e., name it by slide 1, slide 2, etc.). Finally, go to File -> Export Multiple, tick Split files based on Label, and proceed.

Now it's time to go back to PowerPoint and adjust the timing for each slide to make it fit to the length of each narration part (step 4). I added all narration files to VideoLAN playlist to display the time of each narration, and then record the timing in PowerPoint accordingly.
Note that it is alright the timing of a slide could be 0.5 or 1 second longer than its audio narration counterpart. We can trim it later. When this is done, export the video to mp4 format.

The final step is to merge each narration part to the video. To perform this task, I used Video Sequence editor in Blender. While Blender is more well known as an open-source 3D modeling and rendering package, it comes with a surprisingly good video editor.
In Blender, import the video and all audio parts to the Video Sequence editor and start positioning the audio to the video. Finally, 'render' the video and it's done.

More tips for video editing in Blender:

  • The video/audio can be split by positioning the current frame by left click and press 'K'. The selected video/audio will be cut into two parts at the current frame. 
  • Click on the starting and ending arrow of each track and right click and drag to shorten the clip.
  • To remove all gaps, place the cursor to frame 0, and press Shift + Backspace.   
  • Remember to delete the existing sound track in the original video mp4.
  • Export the video by enable Post processing in Rendering tab, set the output path, and hit Animation. 
Hack for the narration:
If you cannot find any native speakers to help with the narration, an alternative is to use text-to-speech engine to make the audio. At the time of this writing (Mar 2016), ispeech.org gives the most realistic sound quality. Unfortunately, it does not allow export to mp3 for free. But fortunately, there is a workaround. Here's how.

  • Install SpeakIt! extension on Google Chrome first. This extension uses iSpeech service to make speech from text. 
  • Play the narration using SpeakIt!. Then use Audacity's Windows WASAPI + loopback device to record the output sound. 


Thursday, March 17, 2016

Compress PDF output by LaTeX

I came across the problem of optimizing an PDF file output by LaTeX from 60 MB to less than 30 MB to fit the requirement of a submission system. The simplest way is perhaps to use GhostScript to compress the pdf. For example

gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -dPDFSETTINGS=/default -sOutputFile=abc_compress.pdf abc.pdf

where abc.pdf is the input file.

There are five settings that one can fiddle to control the trade off between compression ratio and document quality. For images, the more compression we applied, the more downsampling and detail lost one might experience in the output pdf. Here are the settings that can be replaced with /default in the command line above:
  • /ebook 
  • /screen
  • /prepress 
  • /default : largest file size but some compression could still discards image details
  • /printer 
If you are not satisfied with the default image quality produced by GhostScript, it is possible to control to specify the image encoding we need, for example:

gswin64c -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dQUIET -dBATCH -dAutoFilterColorImages=false -dEncodeColorImages=true -dColorImageFilter=/DCTEncode -dColorConversionStrategy=/LeaveColorUnchanged -sOutputFile=abc_compress.pdf abc.pdf 

where
-dAutoFilterColorImages=false turns off default setting for image compression,
-dColorImageFilter=/DCTEncode specify the compression type to be JPEG compression.

If you don't want any compression, replace /DCTEncode by /FlateEncode.
More documentation about the parameters could be found here.

If you don't like working with command lines, give Adobe Acrobat a try in case you haven't installed any. It's free for trial in 30 days.

Any comments are welcome.

Reference:
1. http://www.volkerschatz.com/tex/hiqpdf.html
2. Adobe Distiller parameters documentation. Some are applicable to GhostScript.

Thursday, April 25, 2013

Making MEX in MATLAB R2008a to use Visual Studio 2012

I'm building levmar on my Windows machine and it builds well with Visual C++ 2012 using the existing Makefile that is bundled with levmar package. But I have some problems building the Mex files of Matlab interface for levmar. The problem seems to be because I'm building it with the old lcc compiler, and my Matlab is R2008a, which is pretty outdated.

Unfortunately the latest Microsoft compiler that Matlab R2008a can support is Microsoft Visual C++ 2008. Therefore, I'm looking for a way to make my MATLAB works with Visual C++ 2012. And I found the following steps. Hope this is useful for other people as well.

1. Run mex -setup in MATLAB R2008a.
When the prompt "Would you like mex to locate installed compilers [y]/n? " appears, say No, and select the latest Visual C++ version in the list. Mine is Microsoft Visual C++ 2008.

The purpose in the above step is to let Matlab copy the mexopts.bat into %Appdata%\MathWorks\MATLAB\R2008a folder so we can make modifications on it to make Visual C++ 2012 recognized by Matlab.

2. Navigate to %Appdata%\MathWorks\MATLAB\R2008a. Locate mexopts.bat and open it using Notepad or Notepad++.
For example, on my machine it is C:\Users\Son\AppData\Roaming\MathWorks\MATLAB\R2008a.

3. Look for VS90COMNTOOLS and modify it into VS110COMNTOOLS. This is an environment variable that specifies the installation folder of Visual Studio 2012 (version 11.0).

4. Change the LINKERDIR to
set LINKERDIR=C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A

On your machine you might want to change it accordingly to the Microsoft SDKs folder that contains Bin, Lib, and Include folder, where the Lib folder contains kernel32.lib.

5. Save your mexopts.bat and you are done. Try compiling some Mex files in MATLAB R2008a to make sure it works.

6. Backup your modifed mexopts.bat so next time you accidentally execute mex -setup and the mexopts.bat in the AppData\Roaming\MathWorks folder is overwritten, you have it ready for restore.


Monday, January 28, 2013

Export source code listing to PDF

On Linux, enscript is a tool that can be used to generate source code listing to PDF. For example, I have a C++ source code file named area.cpp and I want to export the source code to PDF format with full syntax highlighting and line numbers.

The following command by enscript can be used:
enscript -Ecpp --color -C -o area.ps area.cpp

Here is the explanation of the above parameters.
-Ecpp: turn on syntax highlighting for C++ style.
--color: export with color fonts.
-o area.ps: save to a PostScript file named area.ps.
-C: include line numbers

To generate PDF, we can simply call
ps2pdf area.ps

Some other interesting options that you can play with:
-G, --fancy-header: add a nice header to each page.
--continuous-page-numbers: no reset of page numbers for each source file.


Thursday, May 03, 2012

A short note about using Canon EDSDK


I had been trying to automate an imaging process using a Canon 40D and Canon EDSDK 2.10. Basically, I wanted the camera to take a picture and send the image (directly from the camera buffer) to my computer. The computer would save/process the image afterwards.

I didn't want to have the camera saved the images on the memory card, since I needed to take a lot of images and I only had a 2 GB card.

I followed the samples in the Canon EDSDK API document and the VC sample code. My code was written in C.

At start, I couldn't have the object event handler worked properly. No object event was detected, even property and camera state events could be found. After countless attempts, I finally know why. I wrote what I found here and hope that it will be useful for other people as well.

1. Add a Windows message loop. 
It seems that the EDSDK relies on the Windows message loop to fire and dispatch events. Without it, no object event can be fired (so the object event handlers are never called).



Note that my code is written in Visual C++ Express 2010, and the subsystem in the project setting is Console (not Windows).

2. Set kEdsPropID_SaveTo property to SaveTo_Host. 



Somehow this property on my camera was set to SaveTo_Camera. Therefore, event 520 (kEdsObjectEvent_DirItemRequestTransfer) had never been fired after a picture was taken. Set it to SaveTo_Host and everything is fine.

3. Catch event kEdsObjectEvent_DirItemCreated
It is possible to retrieve the image from the memory card when kEdsPropID_SaveTo property is set to SaveTo_Camera. The workaround is to catch is event 516 (kEdsObjectEvent_DirItemCreated). As this is more like a trick, I do not recommend using it.

Ensure that the memory card is inserted to the camera. Otherwise, no event 516 can be generated.