From 1787144d7f4b62b73a546aa97418efc9ddc792ed Mon Sep 17 00:00:00 2001 From: Vladimir Eremeev Date: Fri, 9 Aug 2019 12:58:47 +0300 Subject: [PATCH 1/2] use imageio instead of obsolete scipy.ndimage.imread --- cpbd/compute.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpbd/compute.py b/cpbd/compute.py index ea94096..b968964 100644 --- a/cpbd/compute.py +++ b/cpbd/compute.py @@ -11,7 +11,6 @@ from sys import argv import numpy as np -from scipy.ndimage import imread from skimage.feature import canny from cpbd.octave import sobel @@ -206,6 +205,7 @@ def get_block_contrast(block): if __name__ == '__main__': - input_image = imread(argv[1], mode='L') + from imageio import imread + input_image = imread(argv[1], pilmode='L') sharpness = compute(input_image) print('CPBD sharpness for %s: %f' % (argv[1], sharpness)) From 61189fad001bb7e9a32307c144ecc4427b6c2876 Mon Sep 17 00:00:00 2001 From: Vladimir Eremeev Date: Fri, 6 Sep 2019 11:45:31 +0300 Subject: [PATCH 2/2] fix index out of bounds exception for too contrast blocks --- cpbd/compute.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cpbd/compute.py b/cpbd/compute.py index b968964..fc1dd01 100644 --- a/cpbd/compute.py +++ b/cpbd/compute.py @@ -25,9 +25,6 @@ # block size BLOCK_HEIGHT, BLOCK_WIDTH = (64, 64) -# just noticeable widths based on the perceptual experiments -WIDTH_JNB = np.concatenate([5*np.ones(51), 3*np.ones(205)]) - def compute(image): # type: (numpy.ndarray) -> float @@ -145,6 +142,10 @@ def marziliano_method(edges, image): return edge_widths +def _width_JNB(block_contrast): + return 5.0 if block_contrast <= 50 else 3.0 + + def _calculate_sharpness_metric(image, edges, edge_widths): # type: (numpy.array, numpy.array, numpy.array) -> numpy.float64 @@ -173,7 +174,7 @@ def _calculate_sharpness_metric(image, edges, edge_widths): block_widths = block_widths[block_widths != 0] block_contrast = get_block_contrast(image[rows, cols]) - block_jnb = WIDTH_JNB[block_contrast] + block_jnb = _width_JNB(block_contrast) # calculate the probability of blur detection at the edges # detected in the block @@ -206,6 +207,6 @@ def get_block_contrast(block): if __name__ == '__main__': from imageio import imread - input_image = imread(argv[1], pilmode='L') + input_image = imread(argv[1], mode='L') sharpness = compute(input_image) print('CPBD sharpness for %s: %f' % (argv[1], sharpness))