diff --git a/src/image.jl b/src/image.jl new file mode 100644 index 0000000..a34f334 --- /dev/null +++ b/src/image.jl @@ -0,0 +1,8 @@ +using Images + +""" +Converts image to grayscale +""" +function greyscale(c::Images.RGB)::UInt8 + return c.r +end diff --git a/src/tdpacking.jl b/src/tdpacking.jl new file mode 100644 index 0000000..a39c8d4 --- /dev/null +++ b/src/tdpacking.jl @@ -0,0 +1,39 @@ +# Time-dependent packing +struct Rect + pos::Tuple{UInt,UInt} + size::Tuple{UInt,UInt} + color::Real +end + +""" + divide_image(img::BitMatrix, size_min::UInt=16, size_max::UInt=256) + +Divides an image into rectangles of the same colour. The rectangles are not +allowed to have extreme aspect ratios. There is a minimal size of each retangle. +""" +function divide_image(img::Matrix{}, size_min::UInt=16, size_max::UInt=256)::Array{Rect} + result = Rect[] + + # Remaining area + area = sizeof(img) + + # Loop until the entire field is filled + while area > 0 + pos = (9, 9) + size = (threshold, threshold) + region = img.size + + # Try to expand this rectangle to the maximum size + + while size[1] < region[1] || size[2] < region[2] + end + + color = 0.5 + push!(result, Rect(pos, size, color)) + + # Update the boundary markers for the next iteration + area -= size[1] * size[2] + end + + return result +end