Ask Your Question
0

detailsEnchance giving error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor

asked 2017-11-30 23:45:02 -0600

Santhosh1 gravatar image

updated 2017-11-30 23:45:42 -0600

I saw this link which helps enhance details in the image

This is my code

img = cv2.imread('p_45.png',0)
#Enhance the contrast
clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
cl1 = clahe.apply(img)

abs_lp1 = np.absolute(cl1)
i_8U = np.uint8(abs_lp1)

dst = cv2.detailEnhance(i_8U,sigma_s=10, sigma_r=0.15)

This is the error I'm getting

dst = cv2.detailEnhance(img,sigma_s=10, sigma_r=0.15)
cv2.error: /tmp/opencv3-20170817-33981-15wdezm/opencv-3.3.0/modules/imgproc/src/color.cpp:10724: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function cvtColor

What went wrong?

edit retag flag offensive close merge delete

Comments

This is wrong...i_8U = np.uint8(abs_lp1) Look in below code. It is same copied from sp mallick.

supra56 gravatar imagesupra56 ( 2017-12-01 06:15:14 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-12-01 00:49:04 -0600

berak gravatar image

updated 2017-12-01 00:54:58 -0600

you need a 3channel (color) input for this, yours is grayscale

>>> help(cv2.detailEnhance)
Help on built-in function detailEnhance:

detailEnhance(...)
    detailEnhance(src[, dst[, sigma_s[, sigma_r]]]) -> dst
    .   @brief This filter enhances the details of a particular image.
    .
    .   @Param src Input 8-bit 3-channel image.
    .   @Param dst Output image with the same size and type as src.
    .   @Param sigma_s Range between 0 to 200.
    .   @Param sigma_r Range between 0 to 1.
edit flag offensive delete link more

Comments

@berak how do I convert an input image into a 8 bit color image?

Santhosh1 gravatar imageSanthosh1 ( 2017-12-01 01:05:49 -0600 )edit

it tries to convert to Lab, so it will never work with the output from CLAHE

read you image as color one, and feed it straight to detailEnhance()

berak gravatar imageberak ( 2017-12-01 01:16:28 -0600 )edit
1

answered 2017-12-01 06:13:15 -0600

supra56 gravatar image

Try this. It it working.

import cv2

# Read image
im = cv2.imread("cow.jpg")

# Edge preserving filter with two different flags.
imout = cv2.edgePreservingFilter(im, flags=cv2.RECURS_FILTER)
cv2.imwrite("edge-preserving-recursive-filter.jpg", imout)

imout = cv2.edgePreservingFilter(im, flags=cv2.NORMCONV_FILTER)
cv2.imwrite("edge-preserving-normalized-convolution-filter.jpg", imout)

# Detail enhance filter
imout = cv2.detailEnhance(im)
cv2.imwrite("detail-enhance.jpg", imout)

# Pencil sketch filter
imout_gray, imout = cv2.pencilSketch(im, sigma_s=60, sigma_r=0.07, shade_factor=0.05)
cv2.imwrite("pencil-sketch.jpg", imout_gray)
cv2.imwrite("pencil-sketch-color.jpg", imout)

# Stylization filter
cv2.stylization(im,imout)
cv2.imwrite("stylization.jpg", imout)
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-11-30 23:45:02 -0600

Seen: 976 times

Last updated: Dec 01 '17