o0o0o0o0o0o0o / image-processing-from-scratch

This project contains some interesting image processing algorithms that were wrote in python and c++ from scratch.
MIT License
1.07k stars 305 forks source link

ERROR:slice indices must be integers or None or have an __index__ `method` #1

Closed Firesuiry closed 3 years ago

Firesuiry commented 5 years ago
Traceback (most recent call last):
  File "HoughTransform.py", line 94, in <module>
    lines = lines_detector_hough(edge)
  File "HoughTransform.py", line 45, in lines_detector_hough
    eight_neiborhood = accumulator[max(0, result[0,i] - halfThetaWindowSize + 1):min(result[0,i] + halfThetaWindowSize, accumulator.shape[0]), max(0, result[1,i] - halfDistWindowSize + 1):min(result[1,i] + halfDistWindowSize, accumulator.shape[1])]
TypeError: slice indices must be integers or None or have an __index__ `method`
Firesuiry commented 5 years ago

solution:

            maxNum1 = int(max(0, result[0,i] - halfThetaWindowSize + 1))
            maxNum2 = int(max(0, result[1,i] - halfDistWindowSize + 1))
            minNum1 = int(min(result[0,i] + halfThetaWindowSize, accumulator.shape[0]))
            minNum2 = int(min(result[1,i] + halfDistWindowSize, accumulator.shape[1]))

            eight_neiborhood = accumulator[maxNum1:minNum1, maxNum2:minNum2]

change every element to int

o0o0o0o0o0o0o commented 5 years ago

Thanks for pointing out. It runs OK in python2. Maybe there's something different within the max() and min() function in python3. I'll update it to your version for everyone's convenience , or you can start a pull request. Thanks again.

o0o0o0o0o0o0o commented 5 years ago

Nah,Nah.... I got this. It's the '/' operator. In python2, when an integer divide by another integer, you'll still get an integer while in python3 you'll get a real number. So, in python2 the variable 'halfDistWindowSize' will always be an integer. In python3, however, it will be a real number. That's where the problem comes from. Thanks anyway.

o0o0o0o0o0o0o commented 5 years ago

You can correct it just by changing line 26 from: halfDistWindowSize = DistDim/50 to: halfDistWindowSize = int(DistDim/50)

Firesuiry commented 5 years ago

ok~ very thank you for your video on bilibiliļ¼Œleting me get to know what is hough Trans~

o0o0o0o0o0o0o commented 5 years ago

Glad to hear that~ :)

xusang77 commented 5 years ago

Traceback (most recent call last): File "CannyDetection.py", line 207, in img2 = _2_dim_divided_convlove(linear_Gaussian_filter,img) File "CannyDetection.py", line 85, in _2_dim_divided_convlove result = linear_convlove(filter,mat) File "CannyDetection.py", line 70, in linear_convlove result = convlove(filter,mat,[0,0,padding[0],padding[1]],strides) File "CannyDetection.py", line 38, in convlove pad_mat = np.pad(mat, ((padding[0], padding[1]), (padding[2], padding[3])), 'constant') File "C:\Python37\lib\site-packages\numpy\lib\arraypad.py", line 1169, in pad raise TypeError('pad_width must be of integral type.') TypeError: pad_width must be of integral type.