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

1_preprocess #5

Open
cong-code opened this issue Mar 28, 2024 · 8 comments
Open

1_preprocess #5

cong-code opened this issue Mar 28, 2024 · 8 comments

Comments

@cong-code
Copy link

cong-code commented Mar 28, 2024

Why do you need to change the order? image = image.transpose(2, 1, 0)

@lyqun
Copy link
Collaborator

lyqun commented Mar 28, 2024

Hi, the shape of the image loaded from SimpleITK is (z, y, x) with the spacing of (x, y, z). To align the shape order with the spacing, it is necessary to change the shape order.

@cong-code
Copy link
Author

Thanks, I know. However, when you saved the image later, it was not transformed back. Doesn't this mean that the order of the images was changed?

@lyqun
Copy link
Collaborator

lyqun commented Mar 29, 2024

Hi, if we transform back the order of images, we should change the order again when we further process the image (as we record the spacing in the form of (x, y, z)). Hence, to make it convenient, we just save the image without changing the order.

@cong-code
Copy link
Author

Thanks,I see. I have one ploblem: If the resolution is 128, then the blocks generated in the 3_block_save.py file should be changed to base = np.mgrid[:128, :128, :128], offset is set to 0, and blocks = blocks.transpose(0, 2, 1). astype(float) / 127. Is this correct modification?

@lyqun
Copy link
Collaborator

lyqun commented Mar 29, 2024

The purpose of saving CT as blocks is to accelerate the loading speed and save the memory. For example, for a data sample, we should load an array of 256^3. With blocks, we can randomly choose a block to load (i.e., 64^3), which is faster in practice.

For your question, if your resolution is 128^3 and you choose the block size of 128^3, there is no need to conduct step 3. You can directly modify the dataset (https://github.com/xmed-lab/DIF-Net/blob/main/code/dataset.py#L200) to load CT (reshape the CT to [N, 1] or [N,] as block_values) and set the block_coords to np.mgrid[:128, :128, :128] (also reshape to [N, 3]).

@cong-code
Copy link
Author

Yes, Is this correct modification?

image = self.load_ct(name)
block_values = image.reshape(1, -1)
block_values = block_values.transpose(1, 0)
block_coords = np.mgrid[:128, :128, :128]
block_coords = block_coords.reshape(3, -1)
block_coords = block_coords.transpose(1, 0)
points, p_gt = self.sample_points(block_coords, block_values)

@lyqun
Copy link
Collaborator

lyqun commented Mar 29, 2024

It seems that you do not need to extend an additional dimension for the loaded CT. You can just reshape it as [N,] as the additional dimension of p_gt will be extended in https://github.com/xmed-lab/DIF-Net/blob/main/code/dataset.py#L226

@cong-code
Copy link
Author

Ok, I sincerely appreciate your reply. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants