Experiment


In [1]:
using Images
using ImageMagick
using DataFrames
using FileIO
using Colors

In [2]:
img = load("/raided/datasets/sketches_png/png/airplane/1.png")


Out[2]:

In [3]:
dump(img)


Array{ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}}((1111,1111))
  1: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  2: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  3: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  4: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  5: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  ...
  1234317: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  1234318: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  1234319: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  1234320: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255
  1234321: ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}
    val: FixedPointNumbers.Normed{UInt8,8}
      i: UInt8 255

In [4]:
summary(img)


Out[4]:
"1111×1111 Array{Gray{N0f8},2}"

In [5]:
img[2,2]


Out[5]:

In [6]:
for a in img
    println(a.val)
    break
end


1.0N0f8

In [7]:
eltype(img)


Out[7]:
ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}

In [8]:
test = filter(x->x.val==0, img)


Out[8]:

In [9]:
sizeof(test)


Out[9]:
15260

In [10]:
sizeof(img)


Out[10]:
1234321

In [11]:
img = map(x-> x.val, img)


Out[11]:
1111×1111 Array{N0f8,2}:
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 ⋮                                   ⋱                             ⋮      
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8     1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8

In [12]:
image = reshape(img, (1234321,1))


Out[12]:
1234321×1 Array{N0f8,2}:
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 ⋮      
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8
 1.0N0f8

In [13]:
df = convert(DataFrame, image)
head(df)


Out[13]:
x1
11.0N0f8
21.0N0f8
31.0N0f8
41.0N0f8
51.0N0f8
61.0N0f8

In [14]:
a = stack(df)
head(a)


Out[14]:
variablevaluex1

In [15]:
unstack(a, :x1)


MethodError: no method matching unstack(::DataFrames.DataFrame, ::Symbol)
Closest candidates are:
  unstack(::DataFrames.AbstractDataFrame, ::Any, ::Any) at /home/maaster/.julia/v0.5/DataFrames/src/abstractdataframe/reshape.jl:192
  unstack(::DataFrames.AbstractDataFrame, ::Any, ::Any, ::Any) at /home/maaster/.julia/v0.5/DataFrames/src/abstractdataframe/reshape.jl:188
  unstack(::DataFrames.AbstractDataFrame) at /home/maaster/.julia/v0.5/DataFrames/src/abstractdataframe/reshape.jl:225
  ...

In [16]:
d = DataFrame(A=Float64[],B=Float64[])


Out[16]:
AB

In [17]:
transpose = reshape(img, (1, 1234321))


Out[17]:
1×1234321 Array{N0f8,2}:
 1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8  …  1.0N0f8  1.0N0f8  1.0N0f8  1.0N0f8

In [18]:
dump(transpose)
println(sizeof(transpose))


Array{FixedPointNumbers.Normed{UInt8,8}}((1,1234321)) FixedPointNumbers.Normed{UInt8,8}[1.0N0f8 1.0N0f8 … 1.0N0f8 1.0N0f8]
1234321

In [19]:
# df2 = convert(DataFrame, transpose)
# head(df2)

In [ ]: