Skip to content

Commit 1d76738

Browse files
authored
Added Linting
1 parent b59da01 commit 1d76738

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

image_background_subtractor/image_background_subtractor.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,27 @@
66
mp_drawing = mp.solutions.drawing_utils
77
mp_selfie_segmentation = mp.solutions.selfie_segmentation
88

9-
IMAGE_FILES = ['location_to_image/image.jpg'] # You can use multiple Images for removal at a go by just specifying the name of the images in the list.
10-
BG_COLOR = (255,255,255) # White Background
9+
IMAGE_FILES = ['location_to_image/image.jpg'] # You can use multiple Images for removal at a go by just specifying the name of the images in the list.
10+
BG_COLOR = (255, 255, 255) # White Background
1111
with mp_selfie_segmentation.SelfieSegmentation(model_selection=0) as selfie_segmentation:
1212
for idx, file in enumerate(IMAGE_FILES):
1313
image = cv2.imread(file, cv2.IMREAD_UNCHANGED)
1414
image_height, image_width, _ = image.shape
1515
results = selfie_segmentation.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
1616
condition = np.stack((results.segmentation_mask,) * 3, axis=-1) > 0.1
17-
bg_image = np.zeros(image.shape,dtype=np.uint8)
18-
bg_image[:] = BG_COLOR
19-
output_image = np.where(condition,image,bg_image)
17+
bg_image = np.zeros(image.shape, dtype=np.uint8)
18+
bg_image[:] = BG_COLOR
19+
output_image = np.where(condition, image, bg_image)
2020
cv2.imwrite('./white_bg' + str(idx) + '.png', output_image)
2121
# Converting the White Background to Transparent Background.
2222
img = Image.open("./white_bg"+str(idx)+".png")
23-
img = img.convert("RGBA")
23+
img = img.convert("RGBA")
2424
datas = img.getdata()
25-
newData = []
25+
newData = []
2626
for item in datas:
2727
if item[0] == 255 and item[1] == 255 and item[2] == 255:
2828
newData.append((255, 255, 255, 0))
2929
else:
3030
newData.append(item)
3131
img.putdata(newData)
32-
img.save("location_to_store_result/Result"+ str(idx) +".png", "PNG")
33-
34-
32+
img.save("location_to_store_result/Result" + str(idx) + ".png", "PNG")

0 commit comments

Comments
 (0)