- minor revamp of pixelate code for better sizing
authorEric Zavesky <ezavesky@research.att.com>
Mon, 16 Oct 2017 14:50:01 +0000 (09:50 -0500)
committerEric Zavesky <ezavesky@research.att.com>
Mon, 16 Oct 2017 14:50:01 +0000 (09:50 -0500)
README.md
face_privacy_filter/transform_region.py
web_demo/images/commercial_pixelate.jpg

index eaaae2c..1f2da14 100644 (file)
--- a/README.md
+++ b/README.md
@@ -78,9 +78,9 @@ launched locally.  Afterwards, the sample application found in
 [web_demo](web_demo) uses a `localhost` service to classify
 and visualize the results of image classification.
 
-* [DiCaprio celebrity face sample](web_demo/images/face_DiCaprio.jpg) [wikimedia source](https://en.wikipedia.org/wiki/Celebrity#/media/File:Leonardo_DiCaprio_visited_Goddard_Saturday_to_discuss_Earth_science_with_Piers_Sellers_(26105091624)_cropped.jpg)
-* [Schwarzenegger celebrity face sample](web_demo/images/face_Schwarzenegger.jpg) [wikimedia source](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/A._Schwarzenegger.jpg/220px-A._Schwarzenegger.jpg)
-* [Commercial example](web_demo/images/commercial.jpg) [youtube source](https://www.youtube.com/watch?v=34KfCNapnUg)
+* [DiCaprio celebrity face sample](web_demo/images/face_DiCaprio.jpg) ([wikimedia source](https://en.wikipedia.org/wiki/Celebrity#/media/File:Leonardo_DiCaprio_visited_Goddard_Saturday_to_discuss_Earth_science_with_Piers_Sellers_(26105091624)_cropped.jpg))
+* [Schwarzenegger celebrity face sample](web_demo/images/face_Schwarzenegger.jpg) ([wikimedia source](https://upload.wikimedia.org/wikipedia/commons/thumb/0/0f/A._Schwarzenegger.jpg/220px-A._Schwarzenegger.jpg))
+* [Commercial example](web_demo/images/commercial.jpg) ([youtube source](https://www.youtube.com/watch?v=34KfCNapnUg))
 
 
 <table width='100%'>
index f106884..6f92bf6 100644 (file)
@@ -81,9 +81,8 @@ class RegionTransform(BaseEstimator, ClassifierMixin):
                 x_max = min(r[0]+r[2], img.shape[1])
                 y_max = min(r[1]+r[3], img.shape[0])
                 if self.transform_mode=="pixelate":
-                    block_size = round(max(img.shape[0], img.shape[2])/15)
                     img[r[1]:y_max, r[0]:x_max] = \
-                        RegionTransform.pixelate_image(img[r[1]:y_max, r[0]:x_max], block_size)
+                        RegionTransform.pixelate_image(img[r[1]:y_max, r[0]:x_max])
 
             # for now, we hard code to jpg output; TODO: add more encoding output (or try to match source?)
             img_binary = cv2.imencode(".jpg", img)[1].tostring()
@@ -131,9 +130,11 @@ class RegionTransform(BaseEstimator, ClassifierMixin):
 
     # http://www.jeffreythompson.org/blog/2012/02/18/pixelate-and-posterize-in-processing/
     @staticmethod
-    def pixelate_image(img, blockSize):
+    def pixelate_image(img, blockSize=None):
         if not img.shape[0] or not img.shape[1]:
             return img
+        if blockSize is None:
+            blockSize = round(max(img.shape[0], img.shape[2]) / 8)
         ratio = (img.shape[1] / img.shape[0]) if img.shape[0] < img.shape[1] else (img.shape[0] / img.shape[1])
         blockHeight = round(blockSize * ratio)  # so that we cover all image
         for x in range(0, img.shape[0], blockSize):
index 26cf70a..b533938 100644 (file)
Binary files a/web_demo/images/commercial_pixelate.jpg and b/web_demo/images/commercial_pixelate.jpg differ