我正在嘗試使用帶有pydicom的假自定義AN來匿名化登錄號:def an_callback(ds, data_element): if data_element.tag == Tag(0x00080050): data_element.value = '0000000000'ds.walk(an_callback)我想將自定義值而不是'0000000'傳遞給回調函數。我想我可以使用全局變量,但是我想避免這種情況以減少不必要的錯誤。有沒有不使用全局變量的其他方法?編輯:我認為walk是一個特殊的python函數,但它只是ds的一個方法,這是代碼。您可以在此處更改回調的代碼,使其也包含可選參數?;卣{(自我,數據元素,替換值=無)def walk(self, callback, recursive=True): """Iterate through the DataElements and run `callback` on each. Visit all DataElements, possibly recursing into sequences and their datasets. The callback function is called for each DataElement (including SQ element). Can be used to perform an operation on certain types of DataElements. E.g., `remove_private_tags`() finds all private tags and deletes them. DataElement`s will come back in DICOM order (by increasing tag number within their dataset). Parameters ---------- callback A callable that takes two arguments: * a Dataset * a DataElement belonging to that Dataset recursive : bool Flag to indicate whether to recurse into Sequences. """ taglist = sorted(self.keys()) for tag in taglist: with tag_in_exception(tag): data_element = self[tag] callback(self, data_element) # self = this Dataset # 'tag in self' below needed in case callback deleted # data_element if recursive and tag in self and data_element.VR == "SQ": sequence = data_element.value for dataset in sequence: dataset.walk(callback)
添加回答
舉報
0/150
提交
取消