Stock composition version #1
|
@ -0,0 +1,8 @@
|
||||||
|
using Images
|
||||||
|
|
||||||
|
"""
|
||||||
|
Converts image to grayscale
|
||||||
|
"""
|
||||||
|
function greyscale(c::Images.RGB)::UInt8
|
||||||
|
return c.r
|
||||||
|
end
|
|
@ -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
|
Loading…
Reference in New Issue