-
-
Save dcunited001/23787c87cb8b34de264a to your computer and use it in GitHub Desktop.
Problems writing to BufferedImage in clojure
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
(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) | |
)) |
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
(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