So I've tried everything, I've tried to work on ubuntu, on windows, tried every solution online but I don't get it; I'm missing something.
I have this code and I'm trying to run it on my gpu, i'm using windows mainly; I have also acess to ubuntu 16.04 and 18.04 if needed!
import cv2
def shadow_removal (path) :
or_img = cv2.imread(path)
y_cb_cr_img1 = cv2.cvtColor(or_img, cv2.COLOR_BGR2YCrCb)
# covert the BGR image to an YCbCr image
y_cb_cr_img = cv2.cvtColor(or_img, cv2.COLOR_BGR2YCrCb)
# copy the image to create a binary mask later
binary_mask = np.copy(y_cb_cr_img)
# get mean value of the pixels in Y plane
y_mean = np.mean(cv2.split(y_cb_cr_img)[0])
# get standard deviation of channel in Y plane
y_std = np.std(cv2.split(y_cb_cr_img)[0])
# classify pixels as shadow and non-shadow pixels
for i in range(y_cb_cr_img.shape[0]):
for j in range(y_cb_cr_img.shape[1]):
if y_cb_cr_img[i, j, 0] < y_mean - (y_std / 3):
# paint it white (shadow)
binary_mask[i, j] = [255, 255, 255]
else:
# paint it black (non-shadow)
binary_mask[i, j] = [0, 0, 0]
# Using morphological operation
# The misclassified pixels are
# removed using dilation followed by erosion.
kernel = np.ones((3, 3), np.uint8)
erosion = cv2.erode(binary_mask, kernel, iterations=3)
# sum of pixel intensities in the lit areas
spi_la = 0
# sum of pixel intensities in the shadow
spi_s = 0
# number of pixels in the lit areas
n_la = 0
# number of pixels in the shadow
n_s = 0
# get sum of pixel intensities in the lit areas
# and sum of pixel intensities in the shadow
for i in range(y_cb_cr_img.shape[0]):
for j in range(y_cb_cr_img.shape[1]):
if erosion[i, j, 0] == 0 and erosion[i, j, 1] == 0 and erosion[i, j, 2] == 0:
spi_la = spi_la + y_cb_cr_img[i, j, 0]
n_la += 1
else:
spi_s = spi_s + y_cb_cr_img[i, j, 0]
n_s += 1
# get the average pixel intensities in the lit areas
average_ld = spi_la / n_la
# get the average pixel intensities in the shadow
average_le = spi_s / n_s
# difference of the pixel intensities in the shadow and lit areas
i_diff = average_ld - average_le
# get the ratio between average shadow pixels and average lit pixels
ratio_as_al = average_ld / average_le
# added these difference
for i in range(y_cb_cr_img.shape[0]):
for j in range(y_cb_cr_img.shape[1]):
if erosion[i, j, 0] == 255 and erosion[i, j, 1] == 255 and erosion[i, j, 2] == 255:
y_cb_cr_img[i, j] = [y_cb_cr_img[i, j, 0] + i_diff, y_cb_cr_img[i, j, 1] + ratio_as_al,
y_cb_cr_img[i, j, 2] + ratio_as_al]
else:
y_cb_cr_img[i, j] = y_cb_cr_img1[i,j]
# # # covert the YCbCr image to the BGR image
final_image = cv2.cvtColor(y_cb_cr_img, cv2.COLOR_YCR_CB2RGB)
#dilation = cv2.dilate(final_image,kernel,iterations = 1)
cv2.imwrite('im4.png', dilation)
# blur = cv2.GaussianBlur(final_image,(5,5),cv2.BORDER_DEFAULT)
return final_image
if __name__== "__main__":
#shadow_removal(cv2.Umat('im1.png'))
shadow_removal('im1.png')
Any help is much appreciated, for I have been stuck on this for a week now..
Sorry, if my question is not well asked, but i'm new to this forum and to the whole domain; i'm addapting !