Images.jl icon indicating copy to clipboard operation
Images.jl copied to clipboard

Not so canny canny method?

Open JobJob opened this issue 4 years ago • 5 comments

img = rand(RGB{N0f8}, 100, 100)
canny(img, (Percentile(80), Percentile(20)))

Gives a

ERROR: MethodError: no method matching canny(::Array{Gray{Normed{UInt8,8}},2})
Stacktrace:
 [1] canny(::Array{RGB{Normed{UInt8,8}},2}, ::Tuple{Percentile{Int64},Percentile{Int64}}) at Images/7FSUM/src/edge.jl:410

Seems this code just needs to forward the threshold argument: https://github.com/JuliaImages/Images.jl/blob/3951d87ab2ccb06b7b854b42908504e9fa0e7dd9/src/edge.jl#L410-L411

i.e. canny(convert(Array{Gray}, img), threshold, args...) though a warning suggests that maybe it should be canny(Gray.(img), threshold, args...)

JobJob avatar Sep 07 '20 11:09 JobJob

Thanks for reporting this. You are right, line 411 should be forwarding the threshold argument.

zygmuntszpak avatar Sep 08 '20 14:09 zygmuntszpak

@zygmuntszpak Given that ImageEdgeDetection already implements Canny, what's the current status of this issue? My guess is that we only need to properly deprecate the old canny in src/edge.jl in favor of ImageEdgeDetection, and then this issue gets solved?

johnnychen94 avatar Mar 28 '21 04:03 johnnychen94

thinning algorithms have also been implemented in ImageEdgeDetection.jl and they also need to be properly deprecated here in Images.jl I think

ashwanirathee avatar Mar 28 '21 05:03 ashwanirathee

To fix the error you're encountering with the canny function, you need to convert the image to grayscale before applying the Canny edge detection algorithm. Here are steps-

Convert the RGB image to grayscale. Apply the Canny edge detection algorithm to the grayscale image.

Devanik21 avatar Mar 18 '24 13:03 Devanik21

#try this code, it can fix the error using Images using ImageFiltering img = rand(RGB{N0f8}, 100, 100) gray_img = Gray.(img)

canny_img = canny(gray_img, (Percentile(80), Percentile(20)))

Devanik21 avatar Mar 18 '24 13:03 Devanik21