Module: Imogen::AutoCrop::Box

Includes:
OpenCV
Defined in:
lib/imogen/auto_crop/box.rb

Defined Under Namespace

Classes: Best, BoxInfo, Center

Class Method Summary collapse

Class Method Details

.info(grayscale) ⇒ Object



88
89
90
91
# File 'lib/imogen/auto_crop/box.rb', line 88

def self.info(grayscale)
  dims = [grayscale.cols, grayscale.rows]
  squarish?(grayscale) ? Center.new(grayscale).box() : Best.new(grayscale).box()
end

.squarish?(img) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/imogen/auto_crop/box.rb', line 75

def self.squarish?(img)
  if img.is_a? FreeImage::Bitmap
    dims = [img.width, img.height]
    ratio = dims.min.to_f / dims.max
    return ratio >= BoxInfo::SQUARISH
  elsif img.is_a? OpenCV::CvMat
    dims = [img.cols, img.rows]
    ratio = dims.min.to_f / dims.max
    return ratio >= BoxInfo::SQUARISH
  else
    raise "#{img.class.name} is not a FreeImage::Bitmap"
  end
end