mallelapreethi commited on
Commit
28c8a2d
·
verified ·
1 Parent(s): d1323b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -23,22 +23,26 @@ def image_to_sketch(image, kernel_size=1):
23
 
24
  # Function to blur the background of the image
25
  def blur_background(image, blur_strength=31):
26
- # Convert the image to grayscale
27
- gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
28
 
29
- # Use thresholding to create a binary mask
30
- _, mask = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
31
 
32
- # Create the inverse mask
33
- mask_inv = cv2.bitwise_not(mask)
34
 
35
- # Blur the entire image
36
- blurred = cv2.GaussianBlur(image, (blur_strength, blur_strength), 0)
37
 
38
- # Use the mask to combine the original image with the blurred image
39
- background = cv2.bitwise_and(blurred, blurred, mask=mask)
40
- foreground = cv2.bitwise_and(image, image, mask=mask_inv)
41
- combined = cv2.add(background, foreground)
 
 
 
 
42
 
43
  return combined
44
 
@@ -97,7 +101,7 @@ example_image = cv2.imread(example_image_path)
97
  if example_image is not None:
98
  # Convert BGR to RGB for correct color display
99
  example_image_rgb = cv2.cvtColor(example_image, cv2.COLOR_BGR2RGB)
100
- example_image_blurred = blur_background(example_image_rgb)
101
  example_sketch = image_to_sketch(example_image_blurred)
102
 
103
  col1, col2 = st.columns(2)
 
23
 
24
  # Function to blur the background of the image
25
  def blur_background(image, blur_strength=31):
26
+ # # Convert the image to grayscale
27
+ # gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
28
 
29
+ # # Use thresholding to create a binary mask
30
+ # _, mask = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
31
 
32
+ # # Create the inverse mask
33
+ # mask_inv = cv2.bitwise_not(mask)
34
 
35
+ # # Blur the entire image
36
+ # blurred = cv2.GaussianBlur(image, (blur_strength, blur_strength), 0)
37
 
38
+ # # Use the mask to combine the original image with the blurred image
39
+ # background = cv2.bitwise_and(blurred, blurred, mask=mask)
40
+ # foreground = cv2.bitwise_and(image, image, mask=mask_inv)
41
+ # combined = cv2.add(background, foreground)
42
+ ksize = (10, 10)
43
+
44
+ # Using cv2.blur() method
45
+ combined = cv2.blur(image, ksize)
46
 
47
  return combined
48
 
 
101
  if example_image is not None:
102
  # Convert BGR to RGB for correct color display
103
  example_image_rgb = cv2.cvtColor(example_image, cv2.COLOR_BGR2RGB)
104
+ example_image_blurred = blur_background(example_image)
105
  example_sketch = image_to_sketch(example_image_blurred)
106
 
107
  col1, col2 = st.columns(2)