Tech Tips

  1. Uncategorized
  2. 202 view

[Haskell]Input PGM file part1

Target

I could output PGM file with Haskell.
So I want to make a program which read PGM file.

Program

At first only input header and output it.
import System.IO
import System.Environment (getArgs)

main = do
    args <- getArgs
    if length args == 0 then do
        print "usage : ./pgm-input test.pgm"
    else do
        infile <- openFile (head args) ReadMode

        -- Read PGM Header
        pgm_type <- hGetLine infile
        pgm_comment <- hGetLine infile
        pgm_max_brightness <- hGetLine infile
        pgm_size <- hGetLine infile
        hClose infile

        -- Output PGM File
        putStrLn pgm_type
        putStrLn pgm_comment
        putStrLn pgm_max_brightness
        putStrLn pgm_size
Run.
$ ./pgm-input test.pgm
P5
# PGM type grayscale image
255 255
255

Uncategorized recent post

  1. Run Amazon FreeRTOS on M5Stack Core2 for AWS …

  2. Udacity Self-Driving Car Engineer Nanodegree …

  3. Install sbt 1.0.0 and run sample template

  4. Visualization of Neural Network and its Train…

  5. [Machine Learning]Created docker image includ…

関連記事

PAGE TOP