Skip to content

Instantly share code, notes, and snippets.

@dcunited001
Last active December 24, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcunited001/23787c87cb8b34de264a to your computer and use it in GitHub Desktop.
Save dcunited001/23787c87cb8b34de264a to your computer and use it in GitHub Desktop.
Problems writing to BufferedImage in clojure
(ns digits.core
(:use [incanter core charts])
(:require [digits.util :as util]
[digits.mnist :as mnist]
[digits.net :as net]
[digits.draw :as draw])
(:gen-class :main true))
(defn generic-chart [sizex sizey] (function-plot sin sizex sizey))
(defn -main [& args]
(let [sizex 28
sizey 28
labels (:labels (util/read-labels "data/train-labels-idx1-ubyte"))
images (:images (util/read-images "data/train-images-idx3-ubyte"))
digits-chart (generic-chart (* sizex 10) (* sizey 10))]
(doto digits-chart
(add-image 0 0 (draw/digit-image (head images) sizex sizey))
view)
))
(ns digits.draw
(:import (java.awt.image BufferedImage WritableRaster))
(:gen-class))
(defn digit-image [data sizex sizey]
(prn data)
;; getting Exception in thread "main" java.lang.IllegalArgumentException:
;; No matching method found: setPixels for class sun.awt.image.ByteInterleavedRaster
;; even though this method clearly exists!
;; http://www.docjar.com/docs/api/sun/awt/image/ByteInterleavedRaster.html#setPixels(int, int, int, int, int)
(-> (BufferedImage. sizex sizey BufferedImage/TYPE_BYTE_GRAY)
(.getRaster)
(.setPixels 0 0 sizex sizey data)
;; doesn't work, because of type mismatch or something lame
;; (-> (BufferedImage. sizex sizey BufferedImage/TYPE_BYTE_GRAY)
;; (.setRGB 0 0 sizex sizey data 0 sizex))
;;
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment