Skier8402 commited on
Commit
6bc83c0
·
verified ·
1 Parent(s): 2dff6a6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -37
app.py CHANGED
@@ -112,10 +112,9 @@ def create_zip_file(tiles: List[np.ndarray], prefix: str = "tile") -> str:
112
  return zip_path
113
 
114
 
115
- def process_image(image: np.ndarray, tile_size: int, annotation_type: str,
116
- annotation_position: Tuple[int, int]) -> Tuple[List[np.ndarray], str]:
117
  """
118
- Split the input image into tiles, annotate them at specified positions, and create a zip file of the tiles.
119
 
120
  Parameters
121
  ----------
@@ -123,33 +122,23 @@ def process_image(image: np.ndarray, tile_size: int, annotation_type: str,
123
  Input image as a NumPy array.
124
  tile_size : int
125
  Size of each square tile in pixels.
126
- annotation_type : str
127
- Type of annotation to add ("Cross" or "Rectangle").
128
- annotation_position : Tuple[int, int]
129
- (x, y) position for the annotation.
130
 
131
  Returns
132
  -------
133
  Tuple[List[np.ndarray], str]
134
- A tuple containing the list of annotated image tiles and the path to the zip file.
 
 
 
 
 
 
 
 
135
  """
136
  tiles = split_image(image, tile_size)
137
- annotated_tiles = []
138
-
139
- for tile in tiles:
140
- x, y = annotation_position
141
- if annotation_type == "Cross":
142
- center = (x, y)
143
- cv2.drawMarker(tile, center, color=(255, 0, 0), markerType=cv2.MARKER_CROSS,
144
- markerSize=20, thickness=2)
145
- elif annotation_type == "Rectangle":
146
- top_left = (x, y)
147
- bottom_right = (tile.shape[1]-x, tile.shape[0]-y)
148
- cv2.rectangle(tile, top_left, bottom_right, color=(0, 255, 0), thickness=2)
149
- annotated_tiles.append(tile)
150
-
151
- zip_path = create_zip_file(annotated_tiles) if annotated_tiles else ""
152
- return annotated_tiles, zip_path
153
 
154
 
155
  def main():
@@ -170,17 +159,6 @@ def main():
170
  minimum=100, maximum=1000, step=100, value=500, label="Tile Size"
171
  )
172
 
173
- with gr.Row():
174
- annotation_type = gr.Dropdown(
175
- choices=["Cross", "Rectangle"],
176
- value="Rectangle",
177
- label="Annotation Type"
178
- )
179
- annotation_position = gr.Textbox(
180
- label="Annotation Position (x,y)",
181
- placeholder="e.g., 250,250"
182
- )
183
-
184
  with gr.Row():
185
  submit_btn = gr.Button("Process Image")
186
 
@@ -190,7 +168,7 @@ def main():
190
 
191
  submit_btn.click(
192
  fn=process_image,
193
- inputs=[input_image, tile_size, annotation_type, annotation_position],
194
  outputs=[gallery, download_btn],
195
  )
196
 
@@ -198,4 +176,4 @@ def main():
198
 
199
 
200
  if __name__ == '__main__':
201
- main()
 
112
  return zip_path
113
 
114
 
115
+ def process_image(image: np.ndarray, tile_size: int) -> Tuple[List[np.ndarray], str]:
 
116
  """
117
+ Split the input image into tiles and create a zip file of the tiles.
118
 
119
  Parameters
120
  ----------
 
122
  Input image as a NumPy array.
123
  tile_size : int
124
  Size of each square tile in pixels.
 
 
 
 
125
 
126
  Returns
127
  -------
128
  Tuple[List[np.ndarray], str]
129
+ A tuple containing the list of image tiles and the path to the zip file.
130
+
131
+ Examples
132
+ --------
133
+ >>> tiles, zip_path = process_image(image, tile_size=500)
134
+ >>> len(tiles)
135
+ 16
136
+ >>> os.path.exists(zip_path)
137
+ True
138
  """
139
  tiles = split_image(image, tile_size)
140
+ zip_path = create_zip_file(tiles) if tiles else ""
141
+ return tiles, zip_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
 
144
  def main():
 
159
  minimum=100, maximum=1000, step=100, value=500, label="Tile Size"
160
  )
161
 
 
 
 
 
 
 
 
 
 
 
 
162
  with gr.Row():
163
  submit_btn = gr.Button("Process Image")
164
 
 
168
 
169
  submit_btn.click(
170
  fn=process_image,
171
+ inputs=[input_image, tile_size],
172
  outputs=[gallery, download_btn],
173
  )
174
 
 
176
 
177
 
178
  if __name__ == '__main__':
179
+ main()