Skip to content

Commit

Permalink
Issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamalpaneru committed Oct 8, 2017
1 parent 786548b commit 105361e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/xtractor/xtract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
module Xtractor
class Execute

@directory = File.expand_path("cell-files", File.dirname(__FILE__))

def initialize(image)
img = Magick::Image::read(image).first

Expand Down Expand Up @@ -67,14 +65,15 @@ def rows_filter(img)
end



def start(img)
Dir.mkdir('cell-files') if !File.exists?('cell-files')

rows_filter(img)[0..-2].each_with_index do |row, i|
columns_filter(img)[0..-2].each_with_index do |column, j|
x,y= column[1], row[1]
w,h= columns_filter(img)[j+1][0]-x, rows_filter(img)[i+1][0]-y

puts "#{j}x#{i}"
Magick::Image.constitute(w, h, "RGB", img.get_pixels(x,y,w,h).map{ |pixel|
[pixel.red, pixel.green, pixel.blue]}.flatten).write("cell-files/#{j}x#{i}.jpg") do |out|
out.depth=8
Expand All @@ -89,11 +88,25 @@ def start(img)

end
end
collect_hash
collect_hash(img)
end

def collect_hash(img)
api = Azure_API.new
api.request_API
out_final(img)
end

def collect_hash
request_API
def out_final(img)
output_file = File.open('table.tsv', 'w')
rows_filter(img)[0..-2].each_with_index do |row, i|
text_row = []
columns_filter(img)[0..-2].each_with_index do |column, j|
text_row << File.open("cell-files/#{j}x#{i}.txt", 'r').readlines.map{|line| line.strip}.join(" ")
end
output_file.puts( text_row.join("\t"))
end
output_file.close
end

end
Expand Down

0 comments on commit 105361e

Please sign in to comment.