Algorithms

2008-07-20T14:45:56Z
Dave Pawson.  link
Home

Algorithms

Algorithms

I've been playing with some family photographs. Seems fashions change over 100 years or so. The collection varies in size from 70mm square to those large bound family pictures, all formally dressed and posed by the photographer in the studio. The problem it posed was that scanning them at 300dpi they were mainly too big for a web page. Crude and simple I shrunk them to 40% using image magic. Today I looked at a more sophisticated approach. I took a random 1800x1400 pixel 'max' value and tried to write an algorithm to fit all images by shrinking or growing the to this size. I failed miserably. I need to keep the same ratio, but wanted to max out the size for the available screen area, once I have experimented. My final solution was crude but seems to work, though I'm not happy with it. I'm currently reading ISBN0471469122 after reading praise for it on MSM blog. I'm really impressed with it, especially the approaches to test date sets. I generated enough test cases to blow most of my attempts out of the water. Finally finished up with this, x and y are the print size, resx, resy the resulting size

xmax=1800
ymax=1400
If x > y:
     mult=xmax
else:
     mult=y/ymax
resx=x*mult
resy=y*mult
if (resx > xmax):
   sf = xmax/resx
   resx=resx * sf
   resy=resy * sf
if (resy > ymax):
   sf = ymax/resy
   resx=resx * sf
   resy=resy * sf
return resx,resy

Not pretty, but working as wanted.

Keywords: software

Comments (View)

Return to main index