basic bitmap storage
Useful for comparing two JPEG images saved with a different compression ratios.

You can use these pictures for testing (use the full-size version of each):



50% quality JPEG

100% quality JPEG







link to full size 50% image

link to full size 100% image

The expected difference for these two images is 1.62125%

-- demo\rosetta\Percentage_difference_between_images.exw
without js -- (file i/o)
include ppm.e

function split_colour(integer c)
    return sq_div(sq_and_bits(c, {#FF0000,#FF00,#FF}),
                                 {#010000,#0100,#01})
end function

function percentage_diff(sequence img1, img2)
    if length(img1)!=length(img2)
    or length(img1[1])!=length(img2[1]) then
        return "sizes do not match"
    end if
    atom diff = 0
    for i=1 to length(img1) do
        for j=1 to length(img1[i]) do
            integer {r1,g1,b1} = split_colour(img1[i,j]),
                    {r2,g2,b2} = split_colour(img2[i,j])
            diff += abs(r1-r2)+abs(g1-g2)+abs(b1-b2)
        end for 
    end for 
    return 100*diff/(length(img1)*length(img1[1]))/3/255
end function

sequence img1 = read_ppm("Lenna50.ppm"),
         img2 = read_ppm("Lenna100.ppm")
?percentage_diff(img1,img2)

{} = wait_key()
