Percentage difference between images: Difference between revisions

(Realize in F#)
Line 428:
//Percentage difference between 2 images. Nigel Galloway April 18th., 2018
let img50 = new System.Drawing.Bitmap("Lenna50.jpg")
let n = Seq.init(img50.Height*img50.Width) (fun n->img50.GetPixel(n%img50.Width,n/img50.Width))
let img100 = new System.Drawing.Bitmap("Lenna100.jpg")
let diff=Seq.cast<System.Drawing.Color*System.Drawing.Color>(Array2D.init img50.Width img50.Height (fun n g->(img50.GetPixel(n,g),img100.GetPixel(n,g))))|>Seq.fold(fun i (e,l)->i+abs(int(e.R)-int(l.R))+abs(int(e.B)-int(l.B))+abs(int(e.G)-int(l.G))) 0
let g = Seq.init(img100.Height*img100.Width) (fun n->img100.GetPixel(n%img100.Width,n/img100.Width))
printfn "%f" ((float diff)*100.00/(float(img50.Height*img50.Width)*255.0*3.0))</lang>
let diff=Seq.fold2 (fun i (e:System.Drawing.Color) (l:System.Drawing.Color)->i+abs(int(e.R)-int(l.R))+abs(int(e.B)-int(l.B))+abs(int(e.G)-int(l.G))) 0 n g
printfn "%f" ((float diff)*100.00/(float(img50.Height*img50.Width)*255.0*3.0))
</lang>
{{out}}
<pre>
1.774691
</pre>
 
=={{header|Forth}}==
<lang forth>: pixel-diff ( pixel1 pixel2 -- n )
2,172

edits