Skip to content

Commit ff8a9d6

Browse files
committed
Merge pull request #6 from ascribe/pavlolvml_interface
pavlovml interface changes and documentation
2 parents 12e85ef + f082e94 commit ff8a9d6

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

image_match/signature_database_base.py

+22-8
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,24 @@ def __init__(self, k=16, N=63, n_grid=9,
178178

179179
self.gis = ImageSignature(n=n_grid, crop_percentiles=crop_percentile, *signature_args, **signature_kwargs)
180180

181-
def add_image(self, path, img=None):
181+
def add_image(self, path, img=None, bytestream=False):
182182
"""Add a single image to the database
183183
184184
Args:
185185
path (string): path or identifier for image. If img=None, then path is assumed to be
186186
a URL or filesystem path
187-
img (Optional[string]): raw image data. In this case, path will still be stored, but
188-
a signature will be generated from data in img (default None)
187+
img (Optional[string]): usually raw image data. In this case, path will still be stored, but
188+
a signature will be generated from data in img. If bytestream is False, but img is
189+
not None, then img is assumed to be the URL or filesystem path. Thus, you can store
190+
image records with a different 'path' than the actual image location (default None)
191+
bytestream (Optional[boolean]): will the image be passed as raw bytes?
192+
That is, is the 'path_or_image' argument an in-memory image? If img is None but, this
193+
argument will be ignored. If img is not None, and bytestream is False, then the behavior
194+
is as described in the explanation for the img argument
195+
(default False)
189196
190197
"""
191-
rec = make_record(path, self.gis, self.k, self.N, img=img)
198+
rec = make_record(path, self.gis, self.k, self.N, img=img, bytestream=bytestream)
192199
self.insert_single_record(rec)
193200

194201
def search_image(self, path, all_orientations=False, bytestream=False):
@@ -266,7 +273,7 @@ def search_image(self, path, all_orientations=False, bytestream=False):
266273
return r
267274

268275

269-
def make_record(path, gis, k, N, img=None):
276+
def make_record(path, gis, k, N, img=None, bytestream=False):
270277
"""Makes a record suitable for database insertion.
271278
272279
Note:
@@ -281,8 +288,15 @@ def make_record(path, gis, k, N, img=None):
281288
signature
282289
k (int): width of words for encoding
283290
N (int): number of words for encoding
284-
img (Optional[string]): raw image data. In this case, path will still be stored, but
285-
a signature will be generated from data in img (default None)
291+
img (Optional[string]): usually raw image data. In this case, path will still be stored, but
292+
a signature will be generated from data in img. If bytestream is False, but img is
293+
not None, then img is assumed to be the URL or filesystem path. Thus, you can store
294+
image records with a different 'path' than the actual image location (default None)
295+
bytestream (Optional[boolean]): will the image be passed as raw bytes?
296+
That is, is the 'path_or_image' argument an in-memory image? If img is None but, this
297+
argument will be ignored. If img is not None, and bytestream is False, then the behavior
298+
is as described in the explanation for the img argument
299+
(default False)
286300
287301
Returns:
288302
An image record.
@@ -314,7 +328,7 @@ def make_record(path, gis, k, N, img=None):
314328
record = dict()
315329
record['path'] = path
316330
if img is not None:
317-
signature = gis.generate_signature(img, bytestream=True)
331+
signature = gis.generate_signature(img, bytestream=bytestream)
318332
else:
319333
signature = gis.generate_signature(path)
320334

0 commit comments

Comments
 (0)