Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What is the worlds dumbest picture format then?


pbm

    P1
    # feep.pbm
    24 7
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
    0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
    0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
    0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
    0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0


Raw data without any header, I suppose. You must know or guess the width and height to properly decode the image.


Guessing the dimensions of an image with n pixels is equivalent to factoring n, so good luck with that! And only if your luck is really good (prime width and height) will there be a unique solution—actually you still don’t know whether to choose portrait or landscape. It gets even more interesting if you don’t know the number of channels or the pixel format.


Well, you can check if the image matches common resolutions and aspect ratios - if there are 307200 pixels, for example, a pretty good guess is that it's 640x480 (or 480x640). You'd need a human to see if the image looks correct - actually, with a simple GUI, it wouldn't take a human very long at all to figure out the correct aspect ratio. This could probably be automated easily enough using some pattern recognition - the "shearing" pattern caused by guessing the width wrong is pretty linear and well-behaving.


Minimize the gradient ...


No, that's not it at all.

What you just mentioned is actually really easy (if it worked): factoring n where n is up to 10 megapixels.

Factoring up to a few megapixels (e.g. 3648 x 2736) isn't hard at all! At most there are 3159 guesses (square root of number of pixels) before you hit one of the factors - and that's starting at 1, rather than starting at sane minimum aspect ratio.

(It's only when you start trying to factor really large numbers that the problem becomes intractable. For example, the same trick just doesn't apply to a composite number that's 600 digits long. We're talking 6-9 digits, which a tight loop can crunch through faster than a disk read.)

The harder issue is after you do factor it into primes, you still have to combine those primes into a width and height.

For example, 640 x 480 is 307200. Factor that and you get 2^12 * 3 * 5^2.

There's obviously quite a few ways to combine those into two groups (two factors)...

so you're really not done. Probably the best heuristic is to simply count pixels and then compare with common formats.

I suppose you could do your factorization trick, and then try combining the factors in every possible way into two groups, and for any combinations that result in a "sane" aspect ratio, run some kind of vision algorithm to see if there are connected color blobs or something.

it does seem to me that for truly arbitrary pixel counts, the factors help but don't determine a unique choice.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: