プログラミング + アカデミック + 何か面白いこと

  1. Academic
  2. 22 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

Academic recent post

  1. [Just Touch]Microsoft Quantum Development Kit…

  2. Visualization of Neural Network and its Train…

  3. [Machine Learning]Created docker image includ…

  4. [OpenCV][Ruby]Auto check web page design corr…

  5. [MachineLearning]How to introduce to real pro…

関連記事

PAGE TOP