ImageDraw.jl icon indicating copy to clipboard operation
ImageDraw.jl copied to clipboard

[RFC] Redesign the Drawable type

Open johnnychen94 opened this issue 4 years ago • 4 comments

The current ImageDraw design has significantly restricted its possibility to the 2D case, and that's not good in general (even though it's the most common case).

What I have in mind is:

abstract type Drawable end

struct Point{C<:Colorant, N} <: Drawable
    pos::CartesianIndex{N}
    color::C
    thickness::Int
end

struct Polygon{C<:Colorant, N, T<:CartesianIndex} <: Drawable
    vertices::NTuple{N, T}
    border_color::C
    border_width::Int
    fill_color::C
    fill::Bool # whether we need to fill the region with color C
end

struct Layers{A:: PriorityQueue} <: Drawable
    objects::A
end

Basically, each drawable type consists of the whole information on how it can be drawn.

Layers is a simple wrapper on DataStructures.PriortyQueue that controls how individual objects are drawn in one draw call.

Point is not serving as the index, but instead as a real physical "point" with color and thickness information.

This is a draft type design, we could definitely add more information into each drawable struct.

cc: @jiviteshjain @mgautam98

johnnychen94 avatar Jul 23 '20 11:07 johnnychen94

This is so breaking a design that we may want to start a new repo to do this, a more appropriate place for this is in JuliaGraphics because Image is just one of many drawable types:

struct Image{A<:AbstractArray} <: Drawable
    # the axes of image contain all the positional information
    data::A
end

I could initialize it this weekend, in the meantime, we could still continue the devs here.

Edit:

I'm becoming rather ambitious that I'm now considering what graphic processing should be with image processing as one special case of it.

johnnychen94 avatar Jul 23 '20 12:07 johnnychen94

https://xkcd.com/927/ :smile:

Of course, I don't hate reinventing the wheel. My concerns are:

  • Graphics.jl doesn't do much for abstraction and is a bottleneck on the dependency chain (cf. https://github.com/JuliaImages/ImageCore.jl/pull/124).
  • GeometryTypes.jl was discontinued, but it is still used in many packages.

kimikage avatar Jul 24 '20 05:07 kimikage

Yes, this should start as an experiment and I'm not a graphic expert.

I really don't like the hard-coded x, y, width, height in those packages, given that we have much clearer CartesianIndex. Also, it's not a good experience when I get lost in the countless keyword arguments and names.

It should just start as an experimental package, and if it works well, I'll get ImageDraw deprecated.

johnnychen94 avatar Jul 24 '20 06:07 johnnychen94

This sounds very interesting @johnnychen94 . Did you start up a new repo?

tp2750 avatar Jun 19 '22 10:06 tp2750