-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conversion to binary images using ImageMagick and juicypixels
- Loading branch information
0 parents
commit 0f996b1
Showing
1 changed file
with
15 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Codec.Picture | ||
import System.Cmd (system) | ||
import System.Environment (getArgs) | ||
|
||
toBinaryImage :: Either String DynamicImage -> Image PixelYA8 | ||
toBinaryImage = pixelMap (\x -> if x > 128 then PixelYA8 255 100 else PixelYA8 0 100) . extractPixel . extractImage where | ||
extractImage x = let (Right w) = x in w | ||
extractPixel x = let (ImageY8 w) = x in w | ||
|
||
main = do | ||
imageName <- getArgs | ||
system $ "convert " ++ head imageName ++ " -resize 600x600 -gravity Center -extent 600x600 -colorspace Gray " ++ "gs_" ++ head imageName -- ImageMagick | ||
gsImage <- readImage $ "gs_" ++ head imageName | ||
system $ "rm " ++ "gs_" ++ head imageName | ||
writePng ("binary" ++ takeWhile (/= '.') (head imageName) ++ ".png") $ toBinaryImage gsImage |