Importing images using subfloats in LaTeX - latex

I am using subfloats to import 2 .png files in a figure to basically generate subfigures. There's no space between the figures when I compile it. How do I put some white space in between them? And is it possible to convert them to black and white using LaTeX?

Try \vskip 1em between the figures. If this doesn't work, post your nonworking figure code so we can see what's going on.

To put white space in between them, you can throw a \quad—or anything that makes whitespace—in between the subfloats within the figure. Converting to grayscale is not in the graphicx package as far as I can see; all the literature on it says to use an external program. My first instinct is to explore TikZ (a LaTeX package) just because it is so powerful, but I have no idea if it can do anything with external graphics. This Page deals with compile time options to specify a grayscale or color version. For example, if you have all the color images in one folder, you batch convert them to grayscale and put them in a separate folder with identical filenames. Then, at compile time, specify from which folder to get the images. See the comments for the graphicspath implementation.

Related

Changing content of an image by script

In a project we use GIMP to create banners (which are saved in the GIMP native format). All the work is done by humans. But it is often tedious work which consists of replacing one logo with an other logo with the same dimensions or one piece of text with an other piece of text. Sometimes many 100 times.
What is the best way to automatically replace an image (with the same dimensions) or a text in a GIMP file? Does it make more sense to script it within GIMP or is it better to do open heard surgery on the file itself without GIMP? Or is there a command line tool which I can use for this?

Training Tesseract on specific fonts results in empty tr files

I'm working on a college project that involves OCRing a certain digit-code (with a few other characters as seperators - mainly '.','/' etc..) .
that digit code (printed on products for example) is usually in "digital" fonts (e.g. 7-segment-like font, or a pixelated font etc.).
So I am trying to train Tesseract on several digital fonts I've found online, similar to those used with these code.
The thing is, that Tesseract recognizes the tiff files I provide it as blank pages.
Things I've tried:
1. creating a .box file using JTesseract & qt-box (and adjusting the boxes manually) : in this case, the box & tiff are read by Tesseract and I'm getting the output "1 Page", but no characters are recognized and the tr file in blank.
creating a .box file with Tesseract's makebox - in this case no boxes are created at all.
PS - I manage to train it just fine using more traditional fonts (Arial for example)
Any ideas?
Im attaching an image of such an example font.
Thank you!
I managed to work around most of the issues. Posting it in case it could help anyone else:
I did 2 steps to get Tesseract to identify my text:
Image processing on the training images - I've applied some image processing methods (mainly dilate, erode and some blur) to sort of "connect" the pixels in the text that were segmented or separated from one another. Its VERY IMPORTANT to apply the same steps exactly to the images to be fed to the OCR.
I've noticed that simply saving images as TIFF/PNGs via code doesn't save the DPI setting in the header for some reason (and Tesseract identified the as 0 DPI). I assume there's a code-way to do that but I didn't have time, so I just opened the files in Photoshop and saved them from there.
I'm not entirely sure if it was step 1,2 or both that solved my issue, but most characters were eventually identified.

Finding known text in an image (guided OCR)

I'm looking for a way to locate known text within an image.
Specifically, I'm trying to create a tool convert a set of scanned pages into PDFs that support searching and copy+paste. I understand how this is usually done: OCR the page, retaining the position of the text, and then add the text as an invisible layer to the PDF. Acrobat has this functionality built in, and tesseract can output hOCR files (containing the recognized text along with its location), which can be used by hocr2pdf to generate a text layer.
Unfortunately, my source images are rather low quality (at most 150 DPI, with plenty of JPEG artifacts, and non-solid backgrounds behind some of the text), leading to pretty poor OCR results. However, I do have the a copy of the text (sans pictures and layout) that appears on each page.
Matching already known text to it's location on a scanned page seems like it would be much easier to do accurately, but I failed to discover any software with this capability built-in. How can I leverage existing software to do this?
Edit: The text varies in size and font, though passages of it are consistent.
The thought that springs to mind for me would be a cross-correlation. So, I would take the list of words that you know occur on the page and render them one at a time onto a canvas to create a picture of that word. You would need to use a similar font and size as the words in the document - which is what I asked in my comment. Then I would run a normalised cross-correlation of the picture of the word against the scanned image to see where it occurs. I would do all that with ImageMagick which is available for Windows and OSX (use homebrew on OS X) and included in most Linux distros.
So, let's take a screengrab of the second paragraph of your question and look for the word pretty - where you mention pretty poor OCR.
First, you need to render the word pretty onto a white background. The command will be something like this:
convert -background white -fill black -font Times -pointsize 14 label:pretty word.png
Result:
Then perform a normalised cross-correlation using Fred Weinhaus's script from here like this:
normcrosscorr -p word.png scan.png correlation-result.png
Match Coords: (504,30) And Score In Range 0 to 1: (0.999803)
and you can see the coordinates of the match are 504,30.
Result:
Another Idea
Another idea might be to take Google's Tesseract-OCR and replace the standard dictionary with the text file containing the words on the page you are processing...

ImageMagick - Transparent background - Act like Photoshop's "Magic wand"

I'm trying to convert hundreds of images that
Have an unknown subject centered in the image
Have a white background
I've used ImageMagick's convert utility in the following way
convert ORIGINAL.jpg -fuzz 2% -matte -transparent "#FFFFFF" TRANSPARENT.png
The problem is, some of my subjects are within the "white" scale, so, just like the weatherman wearing a green tie, some of my subjects seem to be disitegrating.
Is there any way to solve this via ImageMagick? Are there any alternative solutions? Scripting GIMP?
As you said, GIMP has a magic wand tool that can be used to select continuous areas of the same color, and so it can avoid the "green tie syndrome". The problem is that it may introduce a problem if there is something like a human hair crossing the image (that will seperate some of the white areas). Another common problem, especially with pictures of people, is when they put their hand next to the body and between the hand and the body there is a small hole.
Basically, it is not too hard to create a GIMP script that opens in batch many images, uses the magic wand to select the pixel at some corner (or if desired, in several known fixed places, not just one) and then removes the selection.
If it's hard to find a white area at a fixed spot, it is possible to do a search inside - meaning that the script searches for a white pixel on the borders, and it goes inside gradually in a spiral untill it finds some white pixel. But this is very very unefficient in the basic scripting engine, so I hope you don't need this.
If any of the suggested options above is OK, tell me and I'll create a gimp script for it. It will be even better if you can post some samples images, but I'll try to help even without these.

Generating simple plots within LaTeX

I want to draw a couple of simple bar plots to include in a LaTeX document.
For some reason (unless im missing something), there doesn't appear to be a simple way to generate bar plots in LaTeX.
I could of course generate them in Excel and save them as PDF, but I'd rather have the flexibility of doing them dynamically in LaTeX.
I looked into TikZ, but it seems nobody on the interwebs is using it for a measly barchart (which is what I need it for), and the code below generates a barplot without any axis:
\begin{tikzpicture}[scale=2]
\draw[ycomb, color=gray,line width=0.5cm]
plot coordinates{(1,1) (2,2) (3,3)};
\end{tikzpicture}
What do you use? Am I doing something horribly wrong?
I'd say you want pgfplots: this is built on top of Tikz as a proper plot-drawing interface.
I do not know if you're familiar with gnuplot, that can generate bar plots. There is a "TikZ terminal" (something that outputs TikZ-code) for gnuplot, however, as far as i know, you have to compile it yourself in order to get it working.
I think there's also another "LaTeX terminal" generating pstricks (?) code or something similar.
Can I point you towards Asymptote (Wiki, Gallery). You can make professional looking graphs offline from LaTex processing, but being LaTeX aware. It is a full blown C-ish language for vector graphics and function graphing. The output eventually is encapsulated postscript (eps) which can be displayed directly into LaTeX documents.

Resources