Giter Site home page Giter Site logo

imagez's Introduction

mikera

Mike's general purpose Java library

Lots of good stuff inside including:

  • Maths functions
  • A set of persistent, immutable data structures
  • Bitwise operations and tools
  • Resource handling utility functions
  • GUI utilities
  • Sound utilities
  • Random number generation and algorithms (also available via the Randomz library - https://github.com/mikera/randomz)

Status

Build Status

imagez's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imagez's Issues

Can't provide just one keyword argument to `save`

I get an IllegalArgumentException when I attempt to use imagez's save function with exactly one keyword argument.

Example

I require version 0.12.0 of the library with [mikera.image.core :as imgz] and have the image and file system path defined as img and path respectively.

Specifying no keyword arguments with (imgz/save img path) works fine.

Specifying both keyword arguments with (imgz/save img path :quality 0.5 :progressive false) or (imgz/save img path :quality 0.5 :progressive nil) also work fine.

However, (imgz/save img path :quality 0.5) causes:

Unhandled java.lang.IllegalArgumentException
No value supplied for key: [:quality 0.5]

and (imgz/save img path :progressive false) causes:

Unhandled java.lang.IllegalArgumentException
No value supplied for key: [:progressive false]

How to save image?

0.3.2-SNAPSHOT

Do I need to do something between resizing and saving?

(require '[mikera.image.core :as img])

(img/save (img/resize (buffer-image "/path/to/file.jpg") 200 100)
          "/path/to/thumbnail/file.jpg")
=> IllegalStateException No compression type set!
     javax.imageio.ImageWriteParam.setCompressionQuality (ImageWriteParam.java:1244)

Make filters functional

imagez filters can become IFn instances (probably via deftype) so that then can be applied directly to images.

This enables composable image progessing pipelines, e.g.

(-> image
  (blur)
  (zoom 5))

writing jpg appears to invert colors

Playing around with imagez today; this one-liner unexpectedly inverts the jpg colors.

imagemeh.core=> (require '[mikera.image.core :as mic])
nil
imagemeh.core=> (mic/write (mic/load-image "download.jpg") "inverted.jpg" "jpg")
nil

source and result images attached:

download
inverted

Writing to PNG produces a normal looking image.

Better exception for mikera.image.core/load-image when file isn't a valid image?

Ran into this issue where a file system glob pulled in an invalid file that didn't contain an image. At present, if you try to load an invalid image file you get an NPE, for example with a fairly minimal repro (copying README.md to resource in a vanilla Leiningen project):

(ns imagez-repro.core
  (:require [mikera.image.core :as img]))

(-> (clojure.java.io/resource "README.md")
     clojure.java.io/file
     img/load-image)

produces:

clojure.lang.Compiler$CompilerException: java.lang.NullPointerException

                          clojure.core/eval/invokeStatic  core.clj: 3105
                                                     ...
                            mikera.image.core/load-image  core.clj:   77
               mikera.image.core/load-image/invokeStatic  core.clj:   86
             mikera.image.core/ensure-default-image-type  core.clj:   66
mikera.image.core/ensure-default-image-type/invokeStatic  core.clj:   70
         java.lang.NullPointerException:
clojure.lang.Compiler$CompilerException: java.lang.NullPointerException, compiling:(form-init1473572426971639384.clj:1:9)

It seems like this case could be caught and handled with a more idiomatic Exception? I could take a stab at it given agreement and consensus around what the Exception should be.

core.matrix

Just wondering is there plan to incorporate core.matrix into imagez library, i.e. support input / output type as matrix type? Or will pull request for the sort of patches will be accepted?

No documented opposite to components-rgb

I want to write out to a different (brand new) image. I intend to get a pixel from the first, change it, and write it out to the same position on the brand new image. The problem is that I do not know how to write back out. There seems to be no function or test for this. Is what I am saying in fact the case? Below shows my current example/effort.

(ns my.issue
  (:use [mikera.image.core])
  (:use [mikera.image.colours]))

(def ant (load-image "Ant1.png"))
(def h (height ant))
(def w (width ant))

(defn -main
  "Demonstrates that I do not know how to use this library to read, alter and write back images"
  [& args]
  (println "Image width: " w)
  (println "Image height: " h)
  (let [first-pixel (get-pixel ant 0 0)
        last-pixel (get-pixel ant (dec w) (dec h))
        first-colour (components-rgb first-pixel)
        last-colour (components-rgb last-pixel)
        ;
        ; first-colour and last-colour are human readable
        ; We now try to reverse the process as if we were going to 
        ; write the pixels back to a different image
        ;
        first-rgb (apply rgb first-colour)
        last-rgb (apply rgb last-colour)
        ]
    (println "First pixel:" first-pixel)
    (println "Last pixel:" last-pixel)
    (println "First as colour:" first-colour)
    (println "Last as colour:" last-colour)
    ;
    ; The output of both of these is exactly the same, showing that `apply rgb` is not the
    ; reverse of `components-rgb`. What is the reverse of `components-rgb`?
    ;
    (println "First, that I want to be the same as first pixel:" first-rgb)
    (println "Last, that I want to be the same as last pixel:" last-rgb)
    )
  )

Get/set individual pixels in image

Hi Mike, I'm playing with imagez for a small project.

Right away I wanted to be able to get or set individual pixels in an image. I first went down the hard path of pulling out pixels from the image into a Java array, aseting them, and putting them back using set-pixels. Then I discovered (.setRGB img x y color) which works quite well, though it requires digging into the details of BufferedImage. Would you be open to a PR that wrapped .getRGB and .setRGB into the API you're providing with this library?

Artifacts not in maven

I'm having trouble using this library. Timeouts connecting to repo1.maven.org:443.
If I look at the pom.xml and use my browser to manually find the artifacts then some are missing. Here's an example that can be found:

https://repo1.maven.org/maven2/net/mikera/randomz/0.3.0

And here are the three that can't be found at https://repo1.maven.org/maven2:

net.mikera/cljunit:0.6.0
net.mikera/clojure-utils:0.8.0
net.mikera/mikera-gui:0.3.1

Is it just a wrong configuration of the pom.xml file? Really wanting to use this library again to read images into Clojure data structures.

IIOException Invalid argument to native writeImage

In a basic leiningen project that includes a file sample.jpg:

user> (require '[clojure.java.io :as io] '[mikera.image.core :as img])
nil
user> (io/file "sample.jpg")
#<File sample.jpg>
user> (img/load-image (io/file "sample.jpg"))
#<BufferedImage BufferedImage@7491c6b: type = 2 DirectColorModel: rmask=ff0000 gmask=ff00 bmask=ff amask=ff000000 IntegerInterleavedRaster: width = 1000 height = 667 #Bands = 4 xOff = 0 yOff = 0 dataOffset[0] 0>
user> (img/save (img/load-image (io/file "sample.jpg")) "other.jpg")
IIOException Invalid argument to native writeImage  com.sun.imageio.plugins.jpeg.JPEGImageWriter.writeImage (JPEGImageWriter.java:-2)
user> 

Am I doing something wrong?

get-pixels returns bytes

The get-pixels function used to return an int array, but now it returns bytes. I'm not sure if this is image specific, or maybe something changed in the underlying image representation used in the JDK classes? For both the ant png image used in the readme and some of my test jpegs I'm now getting bytes. Bytes is fine too if it's consistent, but given that the function has a return type hint of ints I thought I'd post an issue.

Switch to lein

Leiningen is probably a better option for most Clojure users

Size of the array returned by get-pixels

Should get-pixels always return an int array like its description says?

Creating a new image and getting its pixels works as I'd expect, i.e. the number of pixels equals the width times the height of the image.

testing.core=> (def block (new-image 10 10))
#'testing.core/block

testing.core=> (def blockpixels (get-pixels block))
#'testing.core/blockpixels

testing.core=> (alength blockpixels)
100

So far, so good. However, when I read a PNG image, things are not that straightforward. For this test I created a 10 px * 10 px image that consists of red pixels only.

testing.core=> (def redbox (load-image-resource "../resources/red.png"))
#'testing.core/redbox

testing.core=> (.getWidth redbox)
10

testing.core=> (.getHeight redbox)
10

testing.core=> (def redpixels (get-pixels redbox))
#'testing.core/redpixels

testing.core=> (alength redpixels)
300

testing.core=> (vec redpixels)
[-1 0 0 -1 0 0 ... -1 0 0]

It seems get-pixels returns a byte array that has separate RGB values for each pixel. And them being bytes, the value 255 actually becomes -1.

As the function uses Java's getDataElements from the Raster class, I checked its docs:

Returns the pixel data for the specified rectangle of pixels in a primitive array of type TransferType. For image data supported by the Java 2D API, this will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.

But I guess that's exactly why there's the ^ints in get-pixels. It just doesn't seem to do the trick. Or am I possibly doing something stupid here?

(I'm using Clojure 1.6.0 and Imagez 0.4.1)

CVE-2005-0406

When running a NVD (National Vulnerability Database) check against this library, CVE-2005-0406 was revealed to be a risk. This check was run using lein nvd check. It is very likely that this vulnerability is due to the dependency com.jhlabs/filters v2.0.235-1, which has the same CVE report. It is unclear if an alternative library can be used to resolve this issue.

Access to imgscalr options

I've been using imagez to scale down JPEG images but I was dissatisfied with the output quality.

Turns out that you can improve it significantly by using the ULTRA_QUALITY method of imgscalr.

would be interesting to make those options accessible.

Parameter ordering

We should modify imagez functions to put the image parameter first, so that they are consistent and more easily composable with ->

Incorrect project.clj information

Your project.clj is not consistent with information in the readme regarding the project identifier. The readme says [net.mikera/imagez "0.6.0"] but project.clj has [imagez "0.5.1-SNAPSHOT"].

How are you building the project?

load image from java.net.URL

I'm trying to get an image from an http url. I manage to (show) and do some transformation but if I try get-pixels, I don't get the same result type as when using the ant image from your samples.

This then fails when I try to (set-pixels bi inet-pixels) with ava.lang.ClassCastException: [B cannot be cast to [I

Eventually (just for context), I want to do a set-rect (set-pixels with x y w h) so I used setDataElement on the raster and got this error.

Extract common colors from images

Do you have plans to add support for the following use case:
extract common colors from the image?

Equivalent to the ImageMagick: convert $FILENAME -depth 4 +dither -colors 7 -unique-colors txt:-

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.