Skip to content

use imageio instead of obsolete scipy.ndimage.imread #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions cpbd/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,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
Expand Down Expand Up @@ -146,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

Expand Down Expand Up @@ -174,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
Expand Down Expand Up @@ -206,6 +206,7 @@ def get_block_contrast(block):


if __name__ == '__main__':
from imageio import imread
input_image = imread(argv[1], mode='L')
sharpness = compute(input_image)
print('CPBD sharpness for %s: %f' % (argv[1], sharpness))