¿Por qué Python genera un error de tiempo de ejecución solo con ciertas imágenes?

Es la tercera pregunta que hago en stackoverflow sobre eso porque cada vez que tengo algunos cambios en la forma en que Python aumenta el tiempo de ejecución erro.

Las preguntas anteriores fueron: aquí y aquí . En la primera pregunta, creo que era una cuestión de memoria, ya que he analizado muchas imágenes, en el segundo caso, el error de ejecución se produce en esta línea

p2 = numpy.percentile(img, 2) 

Y creo que fue un problema de módulo numpy.

pero ahora el error de ejecución ocurre aquí:

 imgbnbin = mh.morph.dilate(gray, disk7) 

En la función de mahotas dilatar.

Las únicas tres imágenes que tengo entre 90 imágenes son las siguientes:

imagen1

imagen2

imagen3

y estas son 2 imágenes de muestra donde el código funciona bien:

imageright1

imageright2

A continuación, está el código de mi función skelfeatures donde obtuve el error de tiempo de ejecución:

 import os import glob import scipy import numpy as np import pymorph as pm import pylab as plb import matplotlib from matplotlib import pyplot as plt import cv2 import mahotas as mh from skimage import morphology from skimage import io from math import sqrt from skimage import data, img_as_float from skimage import exposure from skimage import color from skimage import io, filter from skimage.morphology import erosion, dilation, opening, closing, white_tophat from skimage.morphology import black_tophat, skeletonize, convex_hull_image from skimage.morphology import disk def plot_img_and_hist(img, axes, bins=256): """Plot an image along with its histogram and cumulative histogram. """ img = img_as_float(img) ax_img, ax_hist = axes ax_cdf = ax_hist.twinx() # Display image ax_img.imshow(img, cmap=plt.cm.gray) ax_img.set_axis_off() # Display histogram ax_hist.hist(img.ravel(), bins=bins, histtype='step', color='black') ax_hist.ticklabel_format(axis='y', style='scientific', scilimits=(0, 0)) ax_hist.set_xlabel('Pixel intensity') ax_hist.set_xlim(0, 1) ax_hist.set_yticks([]) # Display cumulative distribution img_cdf, bins = exposure.cumulative_distribution(img, bins) ax_cdf.plot(bins, img_cdf, 'r') ax_cdf.set_yticks([]) return ax_img, ax_hist, ax_cdf import urllib, cStringIO listarough = list() def skelfeatures(path): import copy if (path[0] == "h"): #URL req = urllib.urlopen(path) #cv2.imdecode(arr,0) # load as grayscale arr = np.asarray(bytearray(req.read()), dtype=np.uint8) gray = cv2.imdecode(arr,0) # 'load it as it is' #cv2.imshow('lalala',gray) #if cv2.waitKey() & 0xff == 27: quit() else: #local path print("prima di cv2imread") gray = cv2.imread(path,0) stampac = "no" originale = copy.copy(gray) oshape = list(gray.shape) if (oshape[0] <= 140): #print(oshape[0]/100) ow = int ((oshape[0]/100 )*2.5 ) oh = int ((oshape[0]/100 )*2.5 ) #print("ow ",ow) elif (oshape[0] <= 300): #print(oshape[0]/100) ow = int ((oshape[0]/100 )*3.5 ) oh = int ((oshape[0]/100 )*3.5 ) #print("ow ",ow) else: ow = int ((oshape[0]/100 )*7 ) oh = int ((oshape[0]/100 )*7 ) owclose = ow * 2 element = cv2.getStructuringElement(cv2.MORPH_CROSS,(ow,oh)) graydilate = cv2.erode(gray, element) #imgbnbin ret,thresh = cv2.threshold(gray,127,255,cv2.THRESH_BINARY_INV) gray = thresh proxMax = int((oshape[0]/100 )*22) proxMin = int((oshape[0]/100 )*19) proxGE = 5 proxGEmin = 2 oshape = list(gray.shape) if (oshape[0] <= 140): #print(oshape[0]/100) ow = int ((oshape[0]/100 )*2.5 ) oh = int ((oshape[0]/100 )*2.5 ) #print("ow ",ow) elif (oshape[0] <= 300): #print(oshape[0]/100) ow = int ((oshape[0]/100 )*3.5 ) oh = int ((oshape[0]/100 )*3.5 ) #print("ow ",ow) else: ow = int ((oshape[0]/100 )*7 ) oh = int ((oshape[0]/100 )*7 ) #print(ow) owclose = ow * 2 disko = pm.sedisk(0.2) imgbnbin7 = gray ############################################################ # OPEN ImAGE PATH ############################################################ print("mahotas") img = color.rgb2gray(io.imread(path)) print(type(img)) print("FINE ioimread") from skimage import exposure #print dir(exposure) # Contrast stretching ########################################################################### # THE FIRST TIME WHERE I GOT RUNTIME ERROR, the following line ########################################################################### p2 = np.percentile(img, 2) p98 = np.percentile(img, 98) img_rescale = exposure.rescale_intensity(img, out_range=(0, 1)) # Equalization img_eq = exposure.equalize_hist(img) # Adaptive Equalization img_adapteq = exposure.equalize_adapthist(img, clip_limit=0.03) # Display results '''f, axes = plt.subplots(2, 4, figsize=(8, 4)) ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0]) ax_img.set_title('Low contrast image') y_min, y_max = ax_hist.get_ylim() ax_hist.set_ylabel('Number of pixels') ax_hist.set_yticks(np.linspace(0, y_max, 5)) ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_rescale, axes[:, 1]) ax_img.set_title('Contrast stretching') ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_eq, axes[:, 2]) ax_img.set_title('Histogram equalization') ax_img, ax_hist, ax_cdf = plot_img_and_hist(img_adapteq, axes[:, 3]) ax_img.set_title('Adaptive equalization') ax_cdf.set_ylabel('Fraction of total intensity') ax_cdf.set_yticks(np.linspace(0, 1, 5)) #prevent overlap of y-axis labels plt.subplots_adjust(wspace=0.4) plt.show()''' if ( stampac =="no" ): plt.gray() plt.subplot(121) plt.title("dopo histo") plt.imshow(img) plt.show() binimg = img_adapteq if ( stampac =="no" ): plt.gray() plt.subplot(121) plt.title("dopo conversione") plt.imshow(binimg) plt.show() binimgafter = copy.copy(binimg) threshold = filter.threshold_otsu(img_rescale) gray =( img_rescale shape[1]): shape = shape[0] else: shape = shape[1] if (shape  100 and shape 0) # the function continue... path = "http://i.stack.imgur.com/pzBWU.jpg"