From 85961f7759ba147cb7b65c8d6fedfc94ef483dd7 Mon Sep 17 00:00:00 2001 From: BM Abir Date: Tue, 20 Apr 2021 11:45:06 +0600 Subject: [PATCH 1/2] fix numba deprication warning --- haze_removal.py | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/haze_removal.py b/haze_removal.py index bd0e5a8..174d48f 100644 --- a/haze_removal.py +++ b/haze_removal.py @@ -21,19 +21,24 @@ def open_image(self, img_path): self.dst = np.zeros_like(self.src, dtype=np.double) - @jit - def get_dark_channel(self, radius=7): - print("Starting to compute dark channel prior...") - start = time.time() - tmp = self.src.min(axis=2) - for i in range(self.rows): - for j in range(self.cols): + @staticmethod + # @jit(nopython=True) + def _get_dark_channel(rows,cols,tmp,dark, radius=7): + + for i in range(rows): + for j in range(cols): rmin = max(0,i-radius) - rmax = min(i+radius,self.rows-1) + rmax = min(i+radius,rows-1) cmin = max(0,j-radius) - cmax = min(j+radius,self.cols-1) - self.dark[i,j] = tmp[rmin:rmax+1,cmin:cmax+1].min() - print("time:",time.time()-start) + cmax = min(j+radius,cols-1) + dark[i,j] = tmp[rmin:rmax+1,cmin:cmax+1].min() + return dark + + def get_dark_channel(self, radius=7): + tmp = self.src.min(axis=2) + # get_dark_channel[blockspergrid, threadsperblock]() + # self.dark=self._get_dark_channel[self.blockspergrid, self.threadsperblock](self.rows,self.cols,tmp,self.dark,radius) + self.dark=self._get_dark_channel(self.rows,self.cols,tmp,self.dark,radius) def get_air_light(self): print("Starting to compute air light prior...") @@ -48,19 +53,22 @@ def get_air_light(self): # print(self.Alight) print("time:",time.time()-start) - @jit - def get_transmission(self, radius=7, omega=0.95): - print("Starting to compute transmission...") - start = time.time() - for i in range(self.rows): - for j in range(self.cols): + @staticmethod + # @jit(nopython=True) + def _get_transmission(rows,cols,Alight,src,tran,radius=7, omega=0.95): + + for i in range(rows): + for j in range(cols): rmin = max(0,i-radius) - rmax = min(i+radius,self.rows-1) + rmax = min(i+radius,rows-1) cmin = max(0,j-radius) - cmax = min(j+radius,self.cols-1) - pixel = (self.src[rmin:rmax+1,cmin:cmax+1]/self.Alight).min() - self.tran[i,j] = 1. - omega * pixel - print("time:",time.time()-start) + cmax = min(j+radius,cols-1) + pixel = (src[rmin:rmax+1,cmin:cmax+1]/Alight).min() + tran[i,j] = 1. - omega * pixel + return tran + + def get_transmission(self, radius=7, omega=0.95): + self.tran=self._get_transmission(self.rows,self.cols,self.Alight,self.src,self.tran,radius,omega) def guided_filter(self, r=60, eps=0.001): print("Starting to compute guided filter trainsmission...") From cef88a7ffc22899eae6dc37519f3cbaeeb466e21 Mon Sep 17 00:00:00 2001 From: BM Abir Date: Tue, 20 Apr 2021 11:47:00 +0600 Subject: [PATCH 2/2] numba deprication warning and python fallback fix --- haze_removal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/haze_removal.py b/haze_removal.py index 174d48f..9f14e25 100644 --- a/haze_removal.py +++ b/haze_removal.py @@ -22,7 +22,7 @@ def open_image(self, img_path): @staticmethod - # @jit(nopython=True) + @jit(nopython=True) def _get_dark_channel(rows,cols,tmp,dark, radius=7): for i in range(rows): @@ -54,7 +54,7 @@ def get_air_light(self): print("time:",time.time()-start) @staticmethod - # @jit(nopython=True) + @jit(nopython=True) def _get_transmission(rows,cols,Alight,src,tran,radius=7, omega=0.95): for i in range(rows):