2525from ISAT .configs import STATUSMode , MAPMode , load_config , save_config , CONFIG_FILE , SOFTWARE_CONFIG_FILE , CHECKPOINT_PATH , ISAT_ROOT , CONTOURMode
2626from ISAT .annotation import Object , Annotation
2727from ISAT .widgets .polygon import Polygon , PromptPoint
28+ from ISAT .utils .dicom import load_dcm_as_image
2829import os
2930from PIL import Image
3031import functools
3940from skimage .draw .draw import polygon
4041import requests
4142import orjson
42- import pydicom
43- from ISAT .annotation import get_windowed_image
4443
4544
4645class QtBoxStyleProgressBar (QtWidgets .QProgressBar ):
@@ -209,7 +208,10 @@ def run(self):
209208
210209 image_path = os .path .join (self .mainwindow .image_root , self .mainwindow .files_list [index ])
211210
212- image_data = self .mainwindow .current_label .get_img_data (to_rgb = True )
211+ if image_path .lower ().endswith ('.dcm' ):
212+ image_data = np .array (load_dcm_as_image (image_path ).convert ('RGB' ))
213+ else :
214+ image_data = np .array (Image .open (image_path ).convert ('RGB' ))
213215 try :
214216 features , original_size , input_size = self .sam_encoder (image_data )
215217 except Exception as e :
@@ -1182,31 +1184,16 @@ def show_image(self, index: int, zoomfit: bool=True):
11821184 self .plugin_manager_dialog .trigger_before_image_open (file_path )
11831185
11841186 if file_path .lower ().endswith ('.dcm' ):
1185- self . can_be_annotated = True
1187+ image_data = load_dcm_as_image ( file_path )
11861188 else :
1187- try :
1188- image = Image .open (file_path )
1189- png_palette = image .getpalette ()
1190- if png_palette is not None and file_path .endswith ('.png' ):
1191- self .statusbar .showMessage ('This image might be a label image in VOC format.' )
1192- self .can_be_annotated = False
1193- else :
1194- self .can_be_annotated = True
1195- except Exception as e :
1196- # stausbar show error
1197- self .statusbar .showMessage (str (e ), 5000 )
1198- return
1189+ image_data = Image .open (file_path )
11991190
1200- # load label
1201- if self .can_be_annotated :
1202- self .current_group = 1
1203- _ , name = os .path .split (file_path )
1204- label_path = os .path .join (self .label_root , '.' .join (name .split ('.' )[:- 1 ]) + '.json' )
1205- self .current_label = Annotation (file_path , label_path )
1206- # 载入数据
1207- self .current_label .load_annotation ()
1208- # get image data and info
1209- self .current_label .get_img_data ()
1191+ png_palette = image_data .getpalette ()
1192+ if png_palette is not None and file_path .endswith ('.png' ):
1193+ self .statusbar .showMessage ('This image might be a label image in VOC format.' )
1194+ self .can_be_annotated = False
1195+ else :
1196+ self .can_be_annotated = True
12101197
12111198 if self .can_be_annotated :
12121199 self .actionPolygon .setEnabled (True )
@@ -1231,22 +1218,28 @@ def show_image(self, index: int, zoomfit: bool=True):
12311218 self .view .zoomfit ()
12321219
12331220 # 判断图像是否旋转
1234- if not file_path .lower ().endswith ('.dcm' ):
1235- image_data = Image .open (file_path )
1236- exif_info = image_data .getexif ()
1237- if exif_info and exif_info .get (274 , 1 ) != 1 :
1238- warning_info = '这幅图像包含EXIF元数据,且图像的方向已被旋转.\n 建议去除EXIF信息后再进行标注\n 你可以使用[菜单栏]-[工具]-[处理exif标签]功能处理图像的旋转问题。' \
1239- if self .cfg ['software' ]['language' ] == 'zh' \
1240- else 'This image has EXIF metadata, and the image orientation is rotated.\n Suggest labeling after removing the EXIF metadata.\n You can use the function of [Process EXIF tag] in [Tools] in [Menu bar] to deal with the problem of images.'
1241- QtWidgets .QMessageBox .warning (self , 'Warning' , warning_info , QtWidgets .QMessageBox .Ok )
1221+ exif_info = image_data .getexif ()
1222+ if exif_info and exif_info .get (274 , 1 ) != 1 :
1223+ warning_info = '这幅图像包含EXIF元数据,且图像的方向已被旋转.\n 建议去除EXIF信息后再进行标注\n 你可以使用[菜单栏]-[工具]-[处理exif标签]功能处理图像的旋转问题。' \
1224+ if self .cfg ['software' ]['language' ] == 'zh' \
1225+ else 'This image has EXIF metadata, and the image orientation is rotated.\n Suggest labeling after removing the EXIF metadata.\n You can use the function of [Process EXIF tag] in [Tools] in [Menu bar] to deal with the problem of images.'
1226+ QtWidgets .QMessageBox .warning (self , 'Warning' , warning_info , QtWidgets .QMessageBox .Ok )
12421227
12431228 if self .use_segment_anything and self .can_be_annotated :
12441229 self .segany .reset_image ()
12451230 self .seganythread .index = index
12461231 self .seganythread .start ()
12471232 self .SeganyEnabled ()
12481233
1234+ # load label
12491235 if self .can_be_annotated :
1236+ self .current_group = 1
1237+ _ , name = os .path .split (file_path )
1238+ label_path = os .path .join (self .label_root , '.' .join (name .split ('.' )[:- 1 ]) + '.json' )
1239+ self .current_label = Annotation (file_path , label_path )
1240+ # 载入数据
1241+ self .current_label .load_annotation ()
1242+
12501243 for object in self .current_label .objects :
12511244 try :
12521245 group = int (object .group )
0 commit comments