Project

deepselect

0.0
No commit activity in last 3 years
No release in over 3 years
Provides a method to retrieve the image most similar to the specified image from the array.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.16
~> 10.0
~> 3.0

Runtime

>= 0
 Project Readme

Deepselect

Features

deepselect is a Ruby image recognition library using DeepLearning. This library makes it easy to search for images.

deepselectはDeepLearningを使ったRubyの画像認識ライブラリです。 簡単に画像検索ができます。

Synopsis

require 'rmagick'
require "deepselect"

# 5 coffeeshop logo images (famous in Japan)
image_list = [
	"logo_doutor.jpg", "logo_stmarc.png",
	"logo_komeda.jpeg", "logo_starbucks.png",
	"logo_tully's.jpg"
]

# Read Image
images = image_list.map do |name|
	image_dir = "./images/"+name
	image = Magick::Image.read(image_dir).first
end

# Read another Starbucks Image
starbucks_image = Magick::Image.read("./images/image_starbucks.png").first
puts "input: #{"./images/image_starbucks.png"} " # => ".images/image_starbucks.png"

# Search the array for the image most similar to the given image
selected_image = images.dselect{|dimage| dimage == starbucks_image}
puts "most similar image: #{selected_image.filename}" # => ".images/logo_starbucks.png"

Options

images.dselect(take: "deafult", with: "")  &block

args

  • take: Specify how many of the most similar images to retrieve. Interger 1,2,3... or String "all" are accepted.
  • with: Specify whether to output similarity and index. String are accepted. (ex. "similarity, index" )

As an example, when outputting two images with similarity:

stmark_photo_image = Magick::Image.read("./images/photo_stmarc.jpg").first
selected_image = images.dselect(take: 2, with: "similarity"){|dimage| dimage == stmark_photo_image}
p selected_image
# => [
#       [./images/logo_stmarc.png PNG 542x542 542x542+0+0 DirectClass 8-bit 372kb,  0.9097266348649801],
#       [./images/logo_tully's.jpg JPEG 667x666 667x666+0+0 DirectClass 8-bit 72kb, 0.6602779726625289]
# ]

Cache

By caching feature vectors, the speed of the second search is faster than that of the first search.
If you want to pre-store the feature vectors, use the dinit method.

images.dinit # calc feature vector

selected_image = images.dselect{|dimage| dimage == compare_image}

Installation

install the gem:

gem install deepselect

deepselect requires installation of Menoh and imagemagick.
Please check the page of github Menoh for installation Menoh.

License

deepselect is MIT license.

Note: Thankfully data/VGG16.onnx is download from 'https://www.dropbox.com/s/bjfn9kehukpbmcm/VGG16.onnx?dl=1'.
That model is generated by onnx-chainer from pre-trained model which is uploaded at http://www.robots.ox.ac.uk/%7Evgg/software/very_deep/caffe/VGG_ILSVRC_16_layers.caffemodel
That pre-trained model is released under Creative Commons Attribution License.