Created
December 4, 2016 13:19
-
-
Save mwolicki/2ff31a07f13a4d9d32d7f217fe0cb208 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Drawing | |
let getImage path = | |
let image = Image.FromFile path :?> Bitmap | |
Array2D.init image.Width image.Height (fun w h -> image.GetPixel(w,h)) | |
let saveImage path (a:Color[,]) = | |
let w = a.GetLength 0 | |
let h = a.GetLength 1 | |
use b = new Bitmap(w, h) | |
Array2D.iteri (fun w h color -> b.SetPixel(w,h,color)) a | |
b.Save path | |
let generateImage width height = | |
let rnd = Random() | |
let getRandomPixel _ _ = | |
Color.FromArgb(rnd.Next 255, rnd.Next 255, rnd.Next 255) | |
Array2D.init width height getRandomPixel | |
let imageXor (a:Color [,]) (b:Color [,]) = | |
let colorXor (a:Color) (b:Color) = | |
Color.FromArgb(int a.R ^^^ int b.R, int a.G ^^^ int b.G, int a.B ^^^ int b.B) | |
let w = a.GetLength 0 | |
let h = a.GetLength 1 | |
Array2D.init w h (fun w h -> colorXor a.[w,h] b.[w,h]) | |
let a = getImage "c:/tmp/a.bmp" | |
let b = getImage "c:/tmp/b.bmp" | |
let randomImage = generateImage (a.GetLength 0) (a.GetLength 1) | |
let aXored = imageXor a randomImage | |
let bXored = imageXor b randomImage | |
saveImage "c:/tmp/a-xored.bmp" aXored | |
saveImage "c:/tmp/b-xored.bmp" bXored | |
saveImage "c:/tmp/a-xored-xored.bmp" (aXored|> imageXor randomImage) | |
saveImage "c:/tmp/b-xored-xored.bmp" (bXored|> imageXor randomImage) | |
saveImage "c:/tmp/a-xored-b-xored.bmp" (imageXor aXored bXored) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment