Taking Organic Chemistry, I need to memorize many random items. One of them is the priority group order when determining the IUPAC name. So I wrote a script that would help me memorize the order.
#!/usr/bin/python
#(C) 2009 Tej A. Shah
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
import random
random.seed()
groups = ['carboxylic acids','sulfonic acids', 'esters', 'amides', 'nitriles', 'aldehydes', 'ketones', 'alcohols', 'thiols', 'amines', 'alkenes', 'benzene', 'alkynes', 'none']
ans = '>'
correct = False
while ans != '':
a = 1
b = 1
while a == b:
a = random.randint(0,len(groups) -1)
b = random.randint(0,len(groups) -1)
correct = False
while correct == False:
ans = raw_input(groups[a] + " vs. " + groups[b] + " ")
if ans == '>' :
if a < b : #correct
print "Correct"
correct = True
else :
print "Wrong"
elif ans == '<' :
if a > b: #correct
print "Correct"
correct = True
else :
print "Wrong"
else :
correct = True
ans = ''
print "Done"
As you may have noticed in my flashing images video, I had to get all the images the same size in order to use ffmpeg to convert them into a video. However, since not all the images were the same size, I had to write a script that would put the black borders. So I used Python’s PIL to thumbnail the image and then save with a black border as a png file for ffmpeg to use. Here is the script that I used:
#!/usr/bin/python
#(C) 2009 Tej A. Shah
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import Image
import ImageDraw
from os.path import join, getsize
size = 1920,1080
counter = 0
names = []
for root, dirs, files in os.walk('wedding photos'):
for name in files:
names = names + [os.path.join(root,name)]
names.sort()
for name in names:
print name
newImg = Image.new("RGB",size)
draw = ImageDraw.Draw(newImg)
draw.rectangle((0,0,size),(0,0,0))
del draw
oldImg = Image.open(name)
oldImg.thumbnail( size, Image.ANTIALIAS )
oldImg = oldImg.convert("RGB")
xStartPoint = (size[0] /2) - (oldImg.size[0]/2)
newImg.paste(oldImg, (xStartPoint,0,xStartPoint + oldImg.size[0], size[1]) )
counter = counter +1
if counter < 10:
filename = "000" + str(counter)
elif counter < 100 :
filename = "00" + str(counter)
elif counter < 1000 :
filename = "0" + str(counter)
else:
filename = str(counter)
newImg.save("makeMovie/" + filename + ".png","PNG")
I can’t fit all of my music to my N810, so I decided to write a script that would randomly fill up my N810 with random music until it ran out of space.
# (C) 2009 Tej A. Shah
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import shutil
import random
from os.path import join
shutil.rmtree('/media/N810/Music/')
os.mkdir('/media/N810/Music/')
fileList = []
for root, dirs, files in os.walk('~/Music/'):
for name in files:
fileList.append(os.path.join(root,name))
random.shuffle(fileList)
for f in fileList:
print f
shutil.copy(f,'/media/N810/Music/')
So I am right now studying for the DATs. One part that I am having trouble with is the figure out the angle sizes. So I made a trainer using Qt toolkit. If people are interested in adding more features, I can post it to Sourceforge.
I was recently at Anime Boston and took many photos. One of the things I was wondering was how to convert some of these photos from “real” to anime. For example, here is one pic that I took
And the “perfect” program would convert it to
Which I know is impossible. However, that will not prevent me from trying something. Using the normal GIMP tutorials for making a “pencil sketch”, I made a few trials (which all turned out badly).
However, I did some experimenting to see what other styles I could use and here are some of my results:
Using GIMP oil and overlay style
Oil outline style
Using the tiles and outlines, I made a picture that looks like a 2 year old made it
As I mentioned before, I am still working on which language + API to use for the Photo Viewer/Browser application I am thinking about. For this project, there will be a lot of image loading and manipulation being used. Therefore, I just wanted to do a performance test on each of the language + APIs I am thinking about. Here are the “contenders”:
Java + Swing. I mainly use the ImageIO class to load up the images and the Swing graphics library to do whatever manipulation I need.
wxPython, which is just a Python wrapper for WxWidgets, does have a good number of built-in image manipulation functions that I can use.
Qt (using C++) has a ton of functions that I can use. The only thing that is driving me away from Qt is the fact that it is C++ and putting features like sftp may end up being harder with C++.
So here is the simple test: load up many images that are 2560 x 1920 and resize them as fast as you can. I decided to separate the tests out in hopes of getting a better picture of what is going on.
Results of Testing
Just so we can get this straight, the blue bar is just loading up the image and not doing anything. The orange bar means for each image, resize it to a 320×240 rectangle using linear interpolation. And then the yellow bar is the same as the orange except with bi-linear interpolation. The results are interesting since it first seems like wxPython is very fast compared to Java, but then falls flat into the ground as soon as it does bi-linear filtering. Meanwhile, Java gives about half of the image performance compared to Qt with C++. Do note that this is using the Java6 for Mac OS X so there might be some better performance with the Linux version since it has OpenGL hardware acceleration (but I don’t know if that will help it too much).
PS: If anybody wants to see the source code or do some similar tests, just leave a comment and I will just post the source.
EDIT (July 7th):
Thanks for all the comments. Here are a few responses:
1. Please note that at the end of the day, I have to actually display those images. I don’t want to use PIL because then I would have to convert it again to the wxWidget’s image format in order to display it. PIL could be faster in the resizing of the image, but I doubt it will be faster in the image loading. Perhaps I should do Python + Qt?
2. I use both a mac and linux, so Cocoa or Core Graphics will not work all the time and I really don’t like the idea of using .NET on a Mac.
I decided I wanted to do some more performance tests for the different possible frameworks I might be using. I have not 100% decided to use Java but here are some results from doing a few more test. Here are the numbers in terms of large (8 megapixels) images per second in each method:
All of these were done with two threads since I have a dual-core notebook. So I can almost get double the speed using C++ vs. Java. Soon, I will post results when it comes to resizing images.
Sorry for the late updates. I have been pretty busy lately with the moving to NH and then to MA. But now I finally have a new major project that I want to get on:
An open source photo gallery viewer in Java
It will have the following features:
A pure java implementation
Be able to see photos in a directory without having to open it (I am looking at you stupid Konqueror!)
Be able to do a slideshow with selected files or directories
Be able to have the previous features when loading photos from a remote location (using ftp or ssh)
To do this, I wanted to do a few benchmarks. Doing an informal test, I was able to make my MacBook load about 1.5 photos a second using Java. That is pretty slow. I then added another thread (since my MacBook is dual core) and got it to a little less than 3 photos a second. However, Mac OS 10.5 now has Java6 support for all x86_64 Macs. After that upgrade, I was able to get to 6 photos a second which I think is now acceptable.
I then tested out how much work there is in drawing the photos. Here is an image of the panel that I created using 512 images:
It didn’t take long for to load. Assuming that my parents are odd, most people will not have to suffer a long amount of time for the gallery to load (which will of course loading with a background thread).
Sometimes people need to find the “right” picture for their website or presentation. It may end up being they need to search several locations like “Google Images”, “Yahoo Images” and “Flickr”. However, it is a pain to do this many times. Therefore, I decided to work on a “Universal Image Search”. Using my previous Java3D Image Viewer, I made a new program that can search different locations and help people find the “right” image he/she needs.
For example, I searched for the term “pink”, and this is what I got:
One can quickly view more than 1000 images at once (by scrolling though). Because it uses Java3D, one can scroll though many images and not have to worry about memory constraints (assuming there is a dedicated video card).
I noticed that using regular applications, loading a very large image could take a long time. It would take even longer for me to zoom in and out. So I thought about using OpenGL to view the large images. So I wrote a quick program that would convert an image to a 3D texture, and then allow the user to zoom in at any level smoothly. Think of the program to be like Apple’s OpenGL Image Wall Program, but can translate and zoom a little faster.
This example shows me opening a 3032×2064 image and it would allow me to zoom in and out at 60 frames per second.
I am working on re-doing my height field applicaiton as a Java3D program. The reason why I choose to convert all of my 3D work to Java is for 3 reasons:
No more worries about image formats. Under normal circumstances, one would have to load a C/C++ image library that would be very much dependent on the platform and OS. With Java, I would never have to worry about that
One binary to give to all of my friends and family
It would be interesting to re-write the code in a more object oridented manner. It would be nice to take advantage of Java’s framework.
Currently, the program can convert this:
Into this:
in real time. You can zoom, rotate, etc. I already did the basic height mapping, I just need to make it more “user friendly”.
If you want to get the actual application, please contact me.