How to combine the integral image with the adaptive threshold? [closed]

asked 2018-05-10 22:12:28 -0600

PengGuanjun gravatar image

Hi! The integral image is three-channel. I got it. After converting to a single channel, using adaptive thresholding to process the image ,the result is blank. How to solve it?

import cv2  
import numpy as np  

image = cv2.imread("image.png")
rows,cols,dims=image.shape  

sum = np.zeros((rows,cols),np.int32)  
imageIntegral = cv2.integral(image,sum)

##imageIntegral = imageIntegral.astype(np.uint8)
dst1 = np.zeros((rows,cols)).astype("uint8")
cv2.split(imageIntegral,dst1)

dst = cv2.adaptiveThreshold(dst1, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 75, 10);

cv2.namedWindow('image')
cv2.imshow("image",image)
cv2.namedWindow('imageIntegral')
cv2.imshow("imageIntegral",imageIntegral)
cv2.namedWindow('dst')
cv2.imshow("dst",dst)
cv2.imwrite("1.jpg",dst)
waitKey(0)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-10-21 07:39:41.666104

Comments

  • why are you trying to use an integral image here ?
  • it will have the same number of channels, as the input
  • splitting it into uchar channels does not make any sense (you're loosing all significant bits in the conversion)

  • have a look at the docs , again.

berak gravatar imageberak ( 2018-05-11 02:05:10 -0600 )edit

enter code here

# -*- coding: utf-8 -*-
import sys
import numpy as np
import cv2
def adaptiveThresh(I,winSize,ratio=0.15):
    #第一步:对图像矩阵进行均值平滑
     I_smooth = cv2.boxFilter(I,cv2.CV_32FC1,winSize)
   #I_smooth = cv2.medianBlur(I,winSize)
   #第二步:原图像矩阵与平滑结果做差
    out = I - (1.0-ratio)*I_smooth
   #第三步:对 out 进行全局阈值处理,差值大于等于零,输出值为255,反之为零
    out[out>=0] = 255
    out[out<0] = 0
    out = out.astype(np.uint8)
    return out


if __name__ =="__main__":
    image = cv2.imread("image.png",cv2.IMREAD_GRAYSCALE)
    out = adaptiveThresh(image,(31,31),0.15)
    cv2.imshow("out",out)
    cv2.imwrite("adTh.jpg",out)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

I think this is a fast adaptive t

PengGuanjun gravatar imagePengGuanjun ( 2018-05-11 02:35:12 -0600 )edit

your question is about using integral images, please explain.

berak gravatar imageberak ( 2018-05-11 02:42:06 -0600 )edit