Thursday, January 28, 2010

Wednesday, March 26, 2008

magick... magick... everywhere...

Recently I had a problem while converting a 'png' image into 'jpeg' format. I was using Imagemagick (mogrify command line tool) for this. I used the following command:

%mogrify -format jpg pic.png

Converted 'jpeg' image was totally different from the original 'png' image. Some area of the converted 'jpeg' image was coming black instead of white in the original one.



Then I tried the same thing using GIMP, and I came to know that 'png' format supports layers. So flattening is needed before converting a 'png' image into 'jpeg' because later one does not support layers. So I tried converting the image using following parameters and the result was as good as I wanted it to be :).

%mogrify -format jpg -layers flatten pic.png

Thursday, March 6, 2008

mogrified...

JPEG image compression: Single Step vs Multiple Steps

I got a chance to test this thing in one of my short projects. and the findings were worth noticing.
So, first start with formulating the problem, the problem was:
"Is it better to compress a jpg image in more than one step than in a single step? For example, if I want to compress an image upto 60% then I can do it in a single step i.e. just reduce the quality down to 60% or in multiple steps i.e. first reduce the quality down to 80% then reduce it further to 75% (simple percentage rule 75% of 80% = 60%)."
So which one is better? In order to find out, I collected some sample jpg's from various sources (based on resolution, content present in the image etc) and run the test using open source Imagemagick (open source linux library for images). So I used mogrify (command line tool from the same library) for my task and the results were quite noticeable.
For all images, single step compression was doing better than the later one. And with some particular type of images, there was considerable difference in output sizes (i.e. from single step and multiple steps). These image were large paintings, in which color gradients were smaller (or in other words lesser color-flip boundaries) in comparison to a screenshot of your desktop with 5-6 windows open.
Single step compression implies, compressed image data with some tables (which jpeg library uses to compress and decompress the image) which is an overhead.
Multiple steps compression implies, more number of overheads and each overhead introduces complexity in next compression step.
So the bottom line is: Avoid compressing images in steps (for whatever reasons you want to do it in this way), just do it in a single step... :-)

Tuesday, January 15, 2008

Image Search

How many of you have faced the problem with the image search results from any of the search engines? Have you got, what you were looking, on the first page?
I guess the answer in most of the cases is 'yes' (for the former one) and 'no' (later one). So why does it happen?
Most of the search engines works almost in a same way with the images. Whenever an 'ImageBot' encounters an image on the web, it tries to retrieve the image content specific information in the following manner:
1. It tries to relate the image content with the file name. (i.e. if name of image file is Briteny_spears.jpg, then it stores this info or in other words it labels the image with the name of the file)
2. Search engine looks into HTML META tag and labels the image with the information inside it.
3. It looks for the text around the image and using some heuristics gives some more labels to the image.
4. It can perform some more heuristics i.e. from which page, the page containing the image was referenced etc.

As one can see, if somebody creates an online image gallery for his favorite actress (let say 'Angelina Jolie') and names it 'My First Crush' and names all the image files like 1.jpg, 2.jpg etc. Then the labeling of all the images in the gallery would be awesome :-). Things can get worse if he names all the images using breeds of dog. ("exceptionally" bad example ;-> but there are people who can do this)

So what are the possible solutions?
1. Keep relying on content generator (on the web, I am not talking about the person who actually clicks the photo) and hope they will get smarter and smarter and will put much more relevant information in META tags and around the image.
2. Search engines should draw the first blood. They can ask for user inputs regarding the visual content present inside the image i.e. google image labeler.
3. The third possibility is controlled by actual media generator (the photographers who are clicking thousands of photos everyday). They are the best judges of the content inside the image, so let them put the image related information inside the image file itself. Almost every image file format supports metadata field inside it. So just dump all the information inside it. No need to worry about web developer, whether they are smart or not, whether search engines heuristics are good or not.
4. Last but not the least, do image recognition. Recognize all the objects present in the image and label the image accordingly. (not as hard as finding the answer of the ultimate question but still...)

All in all, future of image search is bright and there are lots of possibilities for making it more and more efficient. cya... :)

and the reasons...

there are no reasons... :)