Skip to content

Commit e14607f

Browse files
new
1 parent 26da848 commit e14607f

9 files changed

Lines changed: 38 additions & 5 deletions

File tree

PyImageLabeling/config.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"window_size":{
33
"margin": 10,
44
"icon": [20, 20],
5+
"icon_tool": [30, 30],
56
"icon_save_marker": [12, 12],
67

78
"graphics_view":{
@@ -155,6 +156,7 @@
155156
{
156157
"name": "contour_filling",
157158
"icon": "filling",
159+
"icon_tool": "filling_tool",
158160
"checkable": true,
159161
"name_view": "Contour Filling",
160162
"tooltip": "Click to activate Move mode. This allows you to move the image around in the viewer by dragging it."
@@ -164,13 +166,15 @@
164166
"name_view": "Paintbrush",
165167
"checkable": true,
166168
"icon": "paint",
169+
"icon_tool": "paint_tool",
167170
"tooltip": "Click to reset the image's position and zoom level to the default view."
168171
},
169172
{
170173
"name": "magic_pen",
171174
"name_view": "Magic Pen",
172175
"checkable": true,
173176
"icon": "magic",
177+
"icon_tool": "magi_tool",
174178
"tooltip": "Click to activate Move mode. This allows you to move the image around in the viewer by dragging it."
175179
}
176180
]
@@ -217,6 +221,7 @@
217221
"name_view": "Eraser",
218222
"checkable": true,
219223
"icon": "eraser",
224+
"icon_tool": "eraser_tool",
220225
"tooltip": "Click to activate the eraser tool, allowing you to erase parts of the image or layer."
221226
},
222227
{
1.01 MB
Loading
1.01 MB
Loading
1.01 MB
Loading
1.01 MB
Loading

PyImageLabeling/model/Core.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,19 @@ def save(self, current_file_path, path_image):
239239
name, format = name.split(".")
240240
format = "png"
241241
save_file = current_file_path + os.sep+name + KEYWORD_SAVE_LABEL + str(self.label.get_label_id()) + "." + format
242-
self.labeling_overlay_pixmap.save(save_file, format)
242+
image = self.labeling_overlay_pixmap.toImage().convertToFormat(QImage.Format.Format_Grayscale8)
243+
244+
# Apply binary threshold
245+
threshold = 1 # any nonzero pixel will become white
246+
for y in range(image.height()):
247+
for x in range(image.width()):
248+
pixel_val = image.pixelColor(x, y).value() # grayscale intensity
249+
if pixel_val > threshold:
250+
image.setPixel(x, y, 0xFFFFFFFF) # white
251+
else:
252+
image.setPixel(x, y, 0xFF000000) # black
253+
254+
image.save(save_file, format.upper())
243255

244256
def remove_save(self, current_file_path, path_image):
245257
name = os.path.basename(path_image)

PyImageLabeling/model/File/Files.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,13 @@ def save(self):
3535
dialog.setOption(QFileDialog.Option.ShowDirsOnly, False)
3636
dialog.setOption(QFileDialog.Option.DontUseNativeDialog, True)
3737
dialog.setViewMode(QFileDialog.ViewMode.Detail)
38-
if dialog.exec():
39-
default_path = dialog.selectedFiles()[0]
38+
dialog.setDirectory(default_path)
39+
dialog.setModal(True)
40+
if dialog.exec() == 0: return
41+
#print("result:", result)
42+
#if dialog.exec():
43+
#print("default_path:", default_path)
44+
default_path = dialog.selectedFiles()[0]
4045
current_file_path = default_path
4146

4247
if len(current_file_path) == 0: return

PyImageLabeling/parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"contour_filling": {"tolerance": 8}, "magic_pen": {"tolerance": 72, "max_pixels": 408780, "method": "RGB"}, "save": {"path": "/home/nicolas/Bureau/ProjetsMAIA/Picels/test"}, "load": {"path": "/home/nicolas/Bureau/ProjetsMAIA/Picels/raw_data", "alpha_color": [255, 255, 255]}, "zoom": {"min_zoom": 0.5, "max_zoom": 100, "plus_zoom_factor": 1.1, "minus_zoom_factor": 0.9}, "paint_brush": {"size": 34}, "eraser": {"size": 12, "absolute_mode": 0}, "labeling_opacity": 45}
1+
{"contour_filling": {"tolerance": 8}, "magic_pen": {"tolerance": 72, "max_pixels": 408780, "method": "RGB"}, "save": {"path": "/home/nicolas/Bureau/ProjetsMAIA/Picels/test"}, "load": {"path": "C:/Users/pimfa/Pictures", "alpha_color": [255, 255, 255]}, "zoom": {"min_zoom": 0.5, "max_zoom": 100, "plus_zoom_factor": 1.1, "minus_zoom_factor": 0.9}, "paint_brush": {"size": 34}, "eraser": {"size": 12, "absolute_mode": 0}, "labeling_opacity": 45}

PyImageLabeling/view/ZoomableGraphicsView.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,19 @@ def __init__(self, view, parent=None):
6060
self.view.minus_zoom_factor = self.data_parameters["zoom"]["minus_zoom_factor"]
6161

6262
self.view.layer_activation = False
63-
63+
6464
def change_cursor(self, name):
65+
try:
66+
cursor_pixmap = QPixmap(Utils.get_icon_path(f"{name}_tool"))
67+
cursor_pixmap = cursor_pixmap.scaled(*self.view.config["window_size"]["icon_tool"])
68+
except:
69+
cursor_pixmap = QPixmap(Utils.get_icon_path(name))
70+
cursor_pixmap = cursor_pixmap.scaled(*self.view.config["window_size"]["icon"])
71+
cursor = QCursor(cursor_pixmap)
72+
self.viewport().setCursor(cursor)
73+
return cursor.pixmap().width(), cursor.pixmap().height()
74+
75+
def change_cursor_n(self, name):
6576
cursor_pixmap = QPixmap(Utils.get_icon_path(name))
6677
cursor_pixmap = cursor_pixmap.scaled(*self.view.config["window_size"]["icon"])
6778
cursor = QCursor(cursor_pixmap)

0 commit comments

Comments
 (0)