Nekshay commited on
Commit
2beace7
·
verified ·
1 Parent(s): 0ddbe26

Update tempo.txt

Browse files
Files changed (1) hide show
  1. tempo.txt +25 -94
tempo.txt CHANGED
@@ -1,98 +1,29 @@
1
  import cv2
2
  import numpy as np
3
 
4
- # Read the image mask (assuming grayscale mask)
5
- mask_path = 'mask_image.png'
6
- mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
7
-
8
- # Convert the mask to binary (thresholding)
9
- _, binary_mask = cv2.threshold(mask, 127, 255, cv2.THRESH_BINARY)
10
-
11
- # Find the coordinates of the bottom-right corner
12
- y_max, x_max = binary_mask.shape
13
- y_max -= 1
14
- x_max -= 1
15
-
16
- # Calculate the length of the line
17
- line_length = int(np.sqrt(x_max ** 2 + y_max ** 2))
18
-
19
- # Define the angle of the line (45 degrees)
20
- angle_degrees = 45
21
- angle_radians = np.deg2rad(angle_degrees)
22
-
23
- # Calculate the slope of the line
24
- slope = np.tan(angle_radians)
25
-
26
- # Initialize the starting position of the line
27
- start_x = x_max
28
- start_y = y_max
29
-
30
- # Move the line towards the top-left corner
31
- while start_x >= 0 and start_y >= 0:
32
- # Calculate the end point of the line
33
- end_x = int(start_x - line_length * np.cos(angle_radians))
34
- end_y = int(start_y - line_length * np.sin(angle_radians))
35
-
36
- # Draw the line on the binary mask
37
- cv2.line(binary_mask, (start_x, start_y), (end_x, end_y), 255, 2)
38
-
39
- # Check if the line touches the mask
40
- if binary_mask[end_y, end_x] == 255:
41
- break
42
-
43
- # Move the line towards the top-left corner
44
- start_x -= 1
45
- start_y -= 1
46
-
47
- # Display or save the image with the line
48
- cv2.imshow('Line Image', binary_mask)
49
- cv2.waitKey(0)
50
- cv2.destroyAllWindows()
51
-
52
-
53
- import cv2
54
- import numpy as np
55
-
56
- def is_pixel_on_line(image, start, end):
57
- # Bresenham's line algorithm
58
- x0, y0 = start
59
- x1, y1 = end
60
- dx = abs(x1 - x0)
61
- dy = abs(y1 - y0)
62
- sx = 1 if x0 < x1 else -1
63
- sy = 1 if y0 < y1 else -1
64
- err = dx - dy
65
-
66
- while True:
67
- # Check if the current pixel is white (255)
68
- if image[y0, x0] == 255:
69
- return True # Pixel is present on the line
70
-
71
- # Check if we have reached the end point
72
- if (x0, y0) == (x1, y1):
73
- break
74
-
75
- e2 = 2 * err
76
- if e2 > -dy:
77
- err -= dy
78
- x0 += sx
79
- if e2 < dx:
80
- err += dx
81
- y0 += sy
82
-
83
- return False # No white pixel is present on the line
84
-
85
- # Read the binary mask image
86
- mask_path = 'mask_image.png'
87
- mask = cv2.imread(mask_path, cv2.IMREAD_GRAYSCALE)
88
-
89
- # Define the start and end coordinates of the line
90
- start_point = (10, 10)
91
- end_point = (100, 100)
92
-
93
- # Check if any white pixel is present on the line
94
- is_pixel_present = is_pixel_on_line(mask, start_point, end_point)
95
- if is_pixel_present:
96
- print("At least one white pixel is present on the line.")
97
  else:
98
- print("No white pixel is present on the line.")
 
1
  import cv2
2
  import numpy as np
3
 
4
+ # Load the mask image
5
+ mask = cv2.imread('mask_image.png', cv2.IMREAD_GRAYSCALE) # Replace 'mask_image.png' with the path to your mask image
6
+
7
+ # Apply Gaussian blur to the image to reduce noise
8
+ blurred = cv2.GaussianBlur(mask, (5, 5), 0)
9
+
10
+ # Apply Hough Circle Transform to detect circles
11
+ circles = cv2.HoughCircles(blurred, cv2.HOUGH_GRADIENT, dp=1, minDist=20, param1=50, param2=30, minRadius=0, maxRadius=0)
12
+
13
+ if circles is not None:
14
+ circles = np.uint16(np.around(circles))
15
+
16
+ # Filter out semicircles based on the position of the circle centers
17
+ semicircles = [circle[0] for circle in circles[0] if circle[1] < mask.shape[0] / 2]
18
+
19
+ # Draw the semicircles on a blank image
20
+ semicircle_image = np.zeros_like(mask)
21
+ for (x, y, r) in semicircles:
22
+ cv2.circle(semicircle_image, (x, y), r, (255, 255, 255), thickness=cv2.FILLED)
23
+
24
+ # Display the image with the semicircles
25
+ cv2.imshow('Semicircles in Mask', semicircle_image)
26
+ cv2.waitKey(0)
27
+ cv2.destroyAllWindows()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  else:
29
+ print("No semicircles found in the image.")