0

I need to resize (and sharpen and rotate) some images on demand to create various resolutions. I have a small development computer (Ivy Celeron @ 2.6GHz). My little test picture takes in the 64 Megapixel (resolution) and 4Megapixel versions of a cute little kitten picture and reduce both versions to 750 x 400 (target size).

One versions use JavaIO + ImgScalr and the other one uses Graphics Magick + im4java.

The 4 Megapixel version takes 270ms per Picture using native JavaIO + scalr and 360ms with GraphicsMagick. A 64 Megapixel picture takes 3100ms to resize using JavaIO + scalr and 4300ms using GraphicsMagick.

Am I missing something here. Most of the time is spend opening and reading the file and saving the result but also scaling is much slower using GraphicsMagick. I understand that those are related to the user of some more advanced algorithms but in the end the result looks really good in both versions but also I did not thought that my 2013 computer is not able to process at least 1000 images per second but makes barely 3 to .3 pictures a second.

So the question goes, what do I do wrong? What are your measures of resizing images? Do I really need a whole server for processing a lets say 10 pictures a second?

** Update **:

Doing some math: 64M / 3seconds = 20M/sec / 2.6GHz = 10Mio/GHz = 1pixel/100 Clock-Cycles. So it seams to be almost ok though. For 4M we have: 3M /.3sec = 9M/sec = 1pix/200 cycles.

So here goes an updated question: Is there a format that might sacrefies Memory in order to fast load an image? The best would be raw/bitmap taking maybe one sec to load since SSD is slow (64M*3 = 192MB, 4M*3=12MB). But is there something in between? I doubt using JPeg with poorer quality will be the deal since it seams to not speed up decompression.

Maybe a zipped bitmap with separated color channels? (Do not laugh!:-)). Maybe some other. How fast was ZIP?

Also an Idea is to provide several resolutions (one time penalty) and use the nearest resolution version available. A 1M resolution would be 4M in memory and should result in 12 Picture conversions per second (argh). I was prepared to see at least a 1000/sec but the leap in computer power seams not to be that big within the last 10 years. I will try and start this in parallel using two or more worker threads. Lets see if this doubles up.

Martin Kersten
  • 5,127
  • 8
  • 46
  • 77
  • *"My little test picture takes in the 64 Megapixel .."* Sorry, what?!? You consider an 8000x8000 pixel image to be 'small'? What exactly is BIG? – Andrew Thompson Oct 05 '13 at 13:57
  • No doubt that 64M is big. GM runs a separate process so startup/shutdown could introduce some overhead which can be eliminated by using gm4java (http://kennethxu.blogspot.com/2013/04/integrate-java-and-graphicsmagick.html). 1000/s is impossible for your little PC with big image, see my test there with large server and small images. Using GM, using size parameter makes a lot of difference in performance also consider scale instead of resize. e.g. gm convert -size 1500x800 source.jpg -scale 750x400 target.jpg – Kenneth Xu Oct 24 '13 at 05:04
  • Kenneth, thanks for the hint. I will look into this within the next week. Thanks a lot! – Martin Kersten Oct 24 '13 at 13:22

2 Answers2

0

64 megapixel image is pretty big. I'd be surprised if any PC could resize 1K / sec of those, or even 10 / sec

You could have a look at this answer for potentially more performant ways (https://stackoverflow.com/a/8365035/234901). Note however, image quality and processing time have a tradeoff.

Community
  • 1
  • 1
Enno Shioji
  • 26,542
  • 13
  • 70
  • 109
0

Looks like nothing is wrong here. I settled with the ImgScalr lib and use ImageIO. Produces the fastest result. Also the jpegs I used are in 97% quality and recompressed (after altering the size). The 64M JPEG has a 5.8MB file size and loads slowly (1.5 secs) but after saving with the default quality I got a 1.8MB file loading in somewhat 0.5 seconds. This makes it more practically.

The software can now autoscale around 50 profile pictures and 260 thumbnails. That is fast enough since it only scales if no copy of the result is stored in the CDN. So everything is fine once again.

I was really shocked I thought about 1k per second but finally having about 50 and on the server around 200 (estimation) is ok though.

Martin Kersten
  • 5,127
  • 8
  • 46
  • 77