%%Matlab program - fig2jpg
figdirectory = 'C:\Documents and Settings\username\Desktop'
fullpath = sprintf('%s/*.fig',figdirectory)
d = dir(fullpath);
length_d = length(d)
if(length_d == 0)
disp('couldnt read the directory details\n');
disp('check if your files are in correct directory\n');
end
startfig = 1
endfig = length_d
for i = startfig:endfig
fname = d(i).name;
fname_input = sprintf('%s/%s',figdirectory,fname)
fname_output = sprintf('%s/%s.jpg',figdirectory,fname)
saveas(openfig(fname_input),fname_output,'jpg');
end
Blog on multiple topics in Image Processing and Visualization and anything else not connected.
Tuesday, July 8, 2008
Convert a series of Matlab figure files in to jpg
This program converts a set of fig files located in a directory in to jpg files. The program runs through the directory and gets a list of fig file names. These files are then read using the ‘openfig’ command and the output is written using ‘saveas’ command. For example, a file named ‘image.fig’ will be read and saved as ‘image.fig.jpg’. The only variable that needs to be changed is the figdirectory Bonus: You can use the parsing directory structure to read any kind of files located in a directory.
Tuesday, May 13, 2008
Setting automatic jobs in Linux
I was working on setting up a cron job for monitoring the machines under my control and so the natural thing was to set a cron job in Linux. I was new to
The crontab command begins with setting the time, date at which a particular job needs to be run. These parameters are set using a crontab file, which can be edited by calling the command
5 * * * * command-to-execute > logfile.log
The number 5 represents the minute at which the command has to be executed. The subsequent values represents the hour, day, month and day of the week (Sunday = 0) respectively. The value * represents all the possible combination. The > pipes the output of the command to a logfile. Once the crontab file has been set, it can be verified using
If you wish that you receive a mail every time the cron runs, add the following line first
MAILTO: johndoe@email.com (Of course, replace it with the correct email address)
So far, everything is easy and good but be careful with the following,
1.Ensure that there is an empty line after the last line of crontab file.
2.For some reason, crontab cannot use the PATH stored by Linux. So ensure that all commands in the crontab file and all the commands and scripts called by crontab are referred with full path.
So instead of calling
Also make sure that all the path in the python file are also referred using full path.
crontab command in Linux but as you will soon see, the command is very simple and hence should be easy to master. There are some nuances that I learnt during the course of the work and I will discuss it at the end.The crontab command begins with setting the time, date at which a particular job needs to be run. These parameters are set using a crontab file, which can be edited by calling the command
crontab -l. In the editor, type the following command5 * * * * command-to-execute > logfile.log
The number 5 represents the minute at which the command has to be executed. The subsequent values represents the hour, day, month and day of the week (Sunday = 0) respectively. The value * represents all the possible combination. The > pipes the output of the command to a logfile. Once the crontab file has been set, it can be verified using
crontab -l. The crontab file can also be written to a text file and loaded using crontab cronfile.txt. The content of the cronfile.txt is same as above.If you wish that you receive a mail every time the cron runs, add the following line first
MAILTO: johndoe@email.com (Of course, replace it with the correct email address)
So far, everything is easy and good but be careful with the following,
1.Ensure that there is an empty line after the last line of crontab file.
2.For some reason, crontab cannot use the PATH stored by Linux. So ensure that all commands in the crontab file and all the commands and scripts called by crontab are referred with full path.
So instead of calling
* 2 * * * python /path/to/file/pythonfile.py
call
* 2 * * * /usr/bin/python /path/to/file/pythonfile.pyAlso make sure that all the path in the python file are also referred using full path.
Wednesday, April 9, 2008
Optical Character Recoginition (OCR) using Tesseract
Recently I had a very interesting project from client who wanted to extract the text (in my case numbers) embedded on thousands of images. My natural choice was to use Tesseract, as it can be scripted and applied to many images in sequenence.
Tesseract is an OCR software, originally developed by Hewlett Packard and currently developed by Google. It is a open source software released under Apache license. Since it is open source, you can get your hands on it and install it on pretty much any operating system. I installed it on a Windows machine under Cygwin and the installation was a breeze.
Tesseract does not have any segmentation methods, no document layout and can only output the recognised text to a file. But its accuracy is good enough for many applications. It was ranked among top 3rd OCR software for the year 1995. Making a call to tesseract is also easy
tesseract data.bmp text.dat [-l langid]
The values within [] are optional. The langid is the the language being recognized. The default language is English. But it also supports French, Italian, German, Spanish.
Since Tesseract does not have any segmentation methods to separate the text from background, the user have to apply these methods using other softwares like ImageMagick, ITK etc. The most common segmentation technique for scanned documents is the Local Adaptive Thresholding. It takes in to account the variation in background intensity across the scanned image and thresholds accordingly. But the right technique has to be chosen depending on the type of image being recognized.
Possible additions to Tesseract
All the text that I needed to decipher in my images were numbers but Tesseract does not have a langid for numbers. Since there are no langid for numbers, Tesseract deciphered some of these numbers as alphabets. If I have time in the future, I will work on creating the langid for numbers as it will be helpful for many people. If you find that it might be helpful for you, I encourage you to create one or contact me and we can work togther.
Tesseract is an OCR software, originally developed by Hewlett Packard and currently developed by Google. It is a open source software released under Apache license. Since it is open source, you can get your hands on it and install it on pretty much any operating system. I installed it on a Windows machine under Cygwin and the installation was a breeze.
Tesseract does not have any segmentation methods, no document layout and can only output the recognised text to a file. But its accuracy is good enough for many applications. It was ranked among top 3rd OCR software for the year 1995. Making a call to tesseract is also easy
tesseract data.bmp text.dat [-l langid]
The values within [] are optional. The langid is the the language being recognized. The default language is English. But it also supports French, Italian, German, Spanish.
Since Tesseract does not have any segmentation methods to separate the text from background, the user have to apply these methods using other softwares like ImageMagick, ITK etc. The most common segmentation technique for scanned documents is the Local Adaptive Thresholding. It takes in to account the variation in background intensity across the scanned image and thresholds accordingly. But the right technique has to be chosen depending on the type of image being recognized.
Possible additions to Tesseract
All the text that I needed to decipher in my images were numbers but Tesseract does not have a langid for numbers. Since there are no langid for numbers, Tesseract deciphered some of these numbers as alphabets. If I have time in the future, I will work on creating the langid for numbers as it will be helpful for many people. If you find that it might be helpful for you, I encourage you to create one or contact me and we can work togther.
Subscribe to:
Posts (Atom)