Skip to content

Commit

Permalink
Added extracting Private DICOM tags fuction update
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh639 committed Mar 20, 2022
1 parent 754adec commit 634d0db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 9 additions & 9 deletions modules/png-extraction/ImageExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
import pathlib
configs = {}

with open('config.json', 'r') as f:
niffler = json.load(f)
print_only_public_headers = bool(niffler['PublicHeadersOnly'])

def initialize_config_and_execute(config_values):
global configs
configs = config_values
Expand All @@ -42,6 +38,7 @@ def initialize_config_and_execute(config_values):

print_images = bool(configs['PrintImages'])
print_only_common_headers = bool(configs['CommonHeadersOnly'])
print_only_public_headers = bool(configs['PublicHeadersOnly'])
depth = int(configs['Depth'])
processes = int(configs['UseProcesses']) # how many processes to use.
flattened_to_level = configs['FlattenedToLevel']
Expand Down Expand Up @@ -93,7 +90,7 @@ def initialize_config_and_execute(config_values):
os.makedirs(failed + "/4")

logging.info("------- Values Initialization DONE -------")
final_res = execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, depth,
final_res = execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, print_only_public_headers, depth,
processes, flattened_to_level, email, send_email, no_splits, is16Bit, png_destination,
failed, maps_directory, meta_directory, LOG_FILENAME, metadata_col_freq_threshold, t_start)
return final_res
Expand Down Expand Up @@ -135,7 +132,7 @@ def get_tuples(plan, outlist = None, key = ""):
outlist.append((key + aa, value))
# appends name, value pair for this file. these are later concatenated to the dataframe
# appends the private tags
if not print_only_public_headers:
if not public_headers_bool:
x = plan.keys()
x = list(x)
for i in x:
Expand All @@ -146,7 +143,8 @@ def get_tuples(plan, outlist = None, key = ""):


def extract_headers(f_list_elem):
nn,ff = f_list_elem # unpack enumerated list
global public_headers_bool
nn,ff, public_headers_bool = f_list_elem # unpack enumerated list
plan = dicom.dcmread(ff, force=True) # reads in dicom file
# checks if this file has an image
c=True
Expand Down Expand Up @@ -318,7 +316,7 @@ def fix_mismatch(with_VRs=['PN', 'DS', 'IS']):
}


def execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, depth,
def execute(pickle_file, dicom_home, output_directory, print_images, print_only_common_headers, print_only_public_headers, depth,
processes, flattened_to_level, email, send_email, no_splits, is16Bit, png_destination,
failed, maps_directory, meta_directory, LOG_FILENAME, metadata_col_freq_threshold, t_start):
err = None
Expand Down Expand Up @@ -379,7 +377,9 @@ def execute(pickle_file, dicom_home, output_directory, print_images, print_only_
# for every item in filelist send data to a subprocess and run extract_headers func
# output is then added to headerlist as they are completed (no ordering is done)
with Pool(core_count) as p:
res= p.imap_unordered(extract_headers, enumerate(chunk))
# we send here print_only_public_headers bool value
file_chunks_list = [tups + (print_only_public_headers,) for tups in enumerate(chunk)]
res= p.imap_unordered(extract_headers, file_chunks_list)
for i,e in enumerate(res):
headerlist.append(e)
data = pd.DataFrame(headerlist)
Expand Down
2 changes: 2 additions & 0 deletions modules/png-extraction/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ The below two fields can be left unmodified for most executions. The default val

* *CommonHeadersOnly*: Do you want the resulting dataframe csv to contain only the common headers? Finds if less than 10% of the rows are missing this column field. To extract all the headers, default is set as _false_.

* *PublicHeadersOnly*: Do you want the resulting dataframe csv to contain only the public headers? Then set it as _true_(default). For extract all the private headers set as _false_.


## Running the Niffler PNG Extractor
```bash
Expand Down

0 comments on commit 634d0db

Please sign in to comment.