Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions labelme/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,15 @@ def __init__(
close=close,
deleteFile=deleteFile,
toggleKeepPrevMode=toggle_keep_prev_mode,
toggle_keep_prev_brightness_contrast=action(
text=self.tr("Keep Previous Brightness/Contrast"),
slot=lambda: self._config.__setitem__(
"keep_prev_brightness_contrast",
not self._config["keep_prev_brightness_contrast"],
),
Comment thread
wkentaro marked this conversation as resolved.
checkable=True,
checked=self._config["keep_prev_brightness_contrast"],
),
delete=delete,
edit=edit,
duplicate=duplicate,
Expand Down Expand Up @@ -763,6 +772,7 @@ def __init__(
fitWidth,
None,
brightnessContrast,
self.actions.toggle_keep_prev_brightness_contrast,
),
)

Expand Down Expand Up @@ -1608,12 +1618,8 @@ def brightnessContrast(self, value: bool, is_initial_load: bool = False):
)
if is_initial_load:
prev_filename: str = self.recentFiles[0] if self.recentFiles else ""
if self._config["keep_prev_brightness"] and prev_filename:
brightness, _ = self.brightnessContrast_values.get(
prev_filename, (None, None)
)
if self._config["keep_prev_contrast"] and prev_filename:
_, contrast = self.brightnessContrast_values.get(
if self._config["keep_prev_brightness_contrast"] and prev_filename:
brightness, contrast = self.brightnessContrast_values.get(
prev_filename, (None, None)
)
if brightness is not None:
Expand Down
14 changes: 14 additions & 0 deletions labelme/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ def validate_config_item(key, value):
raise ValueError(f"Duplicates are detected for config key 'labels': {value}")


def _migrate_config_from_file(config_from_yaml: dict) -> None:
keep_prev_brightness: bool = config_from_yaml.pop("keep_prev_brightness", False)
keep_prev_contrast: bool = config_from_yaml.pop("keep_prev_contrast", False)
if keep_prev_brightness or keep_prev_contrast:
logger.info(
"Migrating old config: keep_prev_brightness={} or keep_prev_contrast={} "
"-> keep_prev_brightness_contrast=True",
keep_prev_brightness,
keep_prev_contrast,
)
config_from_yaml["keep_prev_brightness_contrast"] = True


def get_config(config_file_or_yaml=None, config_from_args=None):
# 1. default config
config = _get_default_config_and_create_labelmerc()
Expand All @@ -59,6 +72,7 @@ def get_config(config_file_or_yaml=None, config_from_args=None):
with open(config_from_yaml) as f:
logger.info(f"Loading config file from: {config_from_yaml}")
config_from_yaml = yaml.safe_load(f)
_migrate_config_from_file(config_from_yaml=config_from_yaml)
update_dict(config, config_from_yaml, validate_item=validate_config_item)

# 3. command line argument or specified config file
Expand Down
3 changes: 1 addition & 2 deletions labelme/config/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ display_label_popup: true
store_data: true
keep_prev: false
keep_prev_scale: false
keep_prev_brightness: false
keep_prev_contrast: false
keep_prev_brightness_contrast: false
logger_level: info

flags: null
Expand Down
Binary file modified labelme/translate/zh_CN.qm
Binary file not shown.
5 changes: 5 additions & 0 deletions labelme/translate/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,11 @@ Polygons</source>
<source>AI Mask Model</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../app.py" line="0"/>
<source>Keep Previous Brightness/Contrast</source>
<translation>保留之前的亮度/对比度</translation>
</message>
</context>
<context>
<name>_IouThresholdWidget</name>
Expand Down