Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize versions #8

Merged
merged 7 commits into from
Oct 11, 2024
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
2 changes: 1 addition & 1 deletion assets/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

1. Install synthlung by running `pip install .`
2. Download the MSD Lung Tumor dataset from [here](https://drive.google.com/drive/folders/1HqEgzS8BV2c7xYNrZdEAnrHk7osJJ--2).
3. Extract the zip file into `/assets/`.
3. Extract the zip file into `/assets/images/`.
4. Run `synthlung format --dataset msd` to adjust dataset format
5. Run `synthlung seed --dataset msd` to extract tumor seeds from the dataset
6. Run `synthlung host --dataset msd` to extract lung masks from the images
17 changes: 10 additions & 7 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
numpy
torch
monai
tqdm
lungmask
pytest
pytest-cov
numpy==1.26.2
torch==2.4.1
monai==1.3.2
tqdm==4.66.5
lungmask==0.2.20
pytest==8.3.3
pytest-cov==5.0.0
requests==2.32.3
nibabel==5.3.0
scikit-image==0.24.0
15 changes: 10 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@
packages=setuptools.find_packages(),
entry_points={"console_scripts": ["synthlung = synthlung.__main__:main"]},
install_requires=[
"numpy",
"torch",
"tqdm",
"monai",
"lungmask"
"numpy==1.26.2",
"torch==2.4.1",
"tqdm==4.66.5",
"monai==1.3.2",
"lungmask==0.2.20",
"pytest==8.3.3",
"pytest-cov==5.0.0",
"requests==2.32.3",
"nibabel==5.3.0",
"scikit-image==0.24.0"
],
classifiers=[
"Programming Language :: Python :: 3",
Expand Down
12 changes: 6 additions & 6 deletions synthlung/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
import json

def seed():
json_file_path = "./assets/source/dataset.json"
json_file_path = "./assets/images/source/dataset.json"

with open(json_file_path, 'r') as json_file:
image_dict = json.load(json_file)
crop_pipeline = TumorCropPipeline()
crop_pipeline(image_dict)
formatter = MSDGenerateJSONFormatter("./assets/seeds/")
formatter = MSDGenerateJSONFormatter("./assets/images/seeds/")
formatter.generate_json()

def format_msd():
Expand All @@ -23,11 +23,11 @@ def format_msd():

def generate_randomized_tumors():
tumor_inserter = InsertTumorPipeline()
json_file_path = "./assets/source/dataset.json"
json_file_path = "./assets/images/source/dataset.json"
with open(json_file_path, 'r') as json_file:
image_dict = json.load(json_file)

json_seed_path = "./assets/seeds/dataset.json"
json_seed_path = "./assets/images/seeds/dataset.json"
with open(json_seed_path, 'r') as json_file:
seeds_dict = json.load(json_file)

Expand All @@ -36,12 +36,12 @@ def generate_randomized_tumors():
def mask_hosts():
lung_masker = LMInferer()
host_masker = LungMaskPipeline(lung_masker)
json_file_path = "./assets/source/dataset.json"
json_file_path = "./assets/images/source/dataset.json"
with open(json_file_path, 'r') as json_file:
image_dict = json.load(json_file)

host_masker(image_dict)
json_generator = HostJsonGenerator('./assets/hosts/')
json_generator = HostJsonGenerator('./assets/images/hosts/')
json_generator.generate_json()

def main():
Expand Down
2 changes: 1 addition & 1 deletion synthlung/utils/dataset_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
LABEL_NII_GZ = 'label.nii.gz'

class MSDImageSourceFormatter(ImageSourceFormatter, JSONGenerator):
def __init__(self, source_directory: str = "./assets/Task06_Lung/", target_directory: str = "./assets/source/") -> None:
def __init__(self, source_directory: str = "./assets/images/Task06_Lung/", target_directory: str = "./assets/images/source/") -> None:
self.target_directory = target_directory
self.source_directory = source_directory

Expand Down
4 changes: 2 additions & 2 deletions synthlung/utils/lung_segmentation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def __init__(self, lungmask_inferer: LMInferer) -> None:
self.compose = Compose([
LoadImaged(keys=['image'], image_only = False),
MaskLungs(lungmask_inferer=self.inferer),
SaveImaged(keys=['mask'], output_dir='./assets/hosts/', output_postfix='', separate_folder=False)
SaveImaged(keys=['mask'], output_dir='./assets/images/hosts/', output_postfix='', separate_folder=False)
])

def __call__(self, image_dict) -> Any:
Expand All @@ -63,7 +63,7 @@ def generate_json(self) -> None:
for filename in os.listdir(self.path):
if filename.endswith((NII_GZ_EXTENSION)):
sample_data = {
"host_image": "./assets/source/msd/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'),
"host_image": "./assets/images/hosts/" + (filename[:filename.index(LABEL_NII_GZ)] + IMAGE_NII_GZ).replace('host_', 'source_'),
"host_label": self.path + filename
}
dataset_json.append(sample_data)
Expand Down
5 changes: 2 additions & 3 deletions synthlung/utils/tumor_isolation_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ def __call__(self, sample:dict) -> Any:


class TumorCropPipeline(object):
monai.config.BACKEND = "Nibabel"
def __init__(self) -> None:
self.compose = Compose([
LoadImaged(keys=['image', 'label'], image_only = False),
TumorSeedIsolationd(image_key='image', label_key='label', image_output_key='seed_image', label_output_key='seed_label'),
RenameSourceToSeed(meta_dict_keys=['seed_image_meta_dict', 'seed_label_meta_dict']),
SaveImaged(keys=['seed_image'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False),
SaveImaged(keys=['seed_label'], output_dir='./assets/seeds/', output_postfix='', separate_folder=False)
SaveImaged(keys=['seed_image'], output_dir='./assets/images/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter),
SaveImaged(keys=['seed_label'], output_dir='./assets/images/seeds/', output_postfix='', separate_folder=False, writer=monai.data.NibabelWriter)
])

def __call__(self, image_dict) -> None:
Expand Down
Loading