Negative values appear in nyul #76
-
How do you do, Sir? When I used nyul, there were some problems. I used nyul_normalizer.fit(images,mask_listt) to make a standard scale for the intensity of a specified area in the image, nyul_normalizer.normalize_image(image,mask) was used to transform the image, but some pixel values in the final image were negative, and the value in the blank area became negative more than 20. But the image I used to get the standard scale didn't have negative values. I don't know if that's normal. Please give me your advice. |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments 2 replies
-
Could you provide the version number of import intensity_normalization
print(intensity_normalization.__version__) Also, can you provide the version of python and numpy that you're using, the way you installed And can you provide a minimal example of the code you used that produced the error? Please provide only the code necessary to produce this problem. Finally, please run the following on the problematic mask and image and also report the output: print(((mask < 0.0) | (mask > 1.0)).sum())
print(mask.shape)
print((image < 0.0).sum())
print(image.shape) |
Beta Was this translation helpful? Give feedback.
-
Hello, Sir. My `intensity_normalization.__version__` is 2.2.3
numpy is version 1.22.1
I think my installation was pip
The software I use is pycharm, anaconda3.9.Windows system.
My code example is as follows
```python
from intensity_normalization.normalize.nyul import NyulNormalize
nyul_normalizer = NyulNormalize()
nyul_normalizer.fit(images,mask_listt)
last = []
for i in number_list:
b = i - 1
mask = nib.load(mask_list[b]).get_fdata()
image = nib.load(image_paths[b]).get_fdata()
last.append(nyul_normalizer.normalize_image(image,mask))
for i in range(20):
normalize = last[i]
b = i + 1
name = zong_learn_paths + str(b)+".nii"
new_image = nib.load(name)
print(new_image)
result_name = zong_new_paths + str(b) + ".nii"
print(b)
nib.Nifti1Image(normalize, new_image.affine).to_filename(result_name)
print(((mask<0.0) & (mask>1.0)).sum())
print(mask.shape)
print((image<0.0).sum()
print(image.shape)
```
Since almost all of my processed images had the problems I described, I used one separately
```python
import nibabel as nib
image = nib.load("lunkuo_C_1.nii").get_fdata()
mask = nib.load("mask1.nii").get_fdata()
print(((mask < 0.0) & (mask > 1.0)).sum())
print(mask.shape)
print((image < 0.0).sum())
print(image.shape)
>> D:\anaconda\python.exe D:\Desktop\STUDY\pythonProject65\main.py
>> 0
>> (512, 512, 88)
>> 0
>> (512, 512, 88)
```
Process finished with exit code 0
This is the question you requested. I hope I can get your help. Thank you.
|
Beta Was this translation helpful? Give feedback.
-
The other thing Sir Is that I got landmarks, but a lot of them are [0,0,0,0,0,0,0,0,0]
```python
for i in number_list:
tryy = nib.load("D:/Desktop/STUDY/pythonProject63/learn/lunkuo_C_"+str(i)+".nii").get_fdata()
landmarks =nyul_normalizer.get_landmarks(tryy)
print(landmarks)
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[ 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
115.67621613]
[ 0. 0. 0. 0. 0.
0. 0. 0. 0. 0.
246.93016052]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
```
|
Beta Was this translation helpful? Give feedback.
-
In the email I just replied to you, there was a space error when I copied the code, which should be like this
|
Beta Was this translation helpful? Give feedback.
-
Could you re-run this command. There's a typo in the code I originally sent which I edited, but you ran the buggy version. Please run this: print(((mask < 0.0) | (mask > 1.0)).sum()) Also, please run this: print((image <= 0.0).mean()) Could you tell me what type of image you're trying to process? e.g., MPRAGE of an adult human. |
Beta Was this translation helpful? Give feedback.
-
Hello Sir, when I run the first code Print `(((mask< 0.0) | (mask >1.0)).sum())` when my mask output 0, when the second code my image (I understand that you asked me to run is my original image before processing) output a number like 0.9686437280554521, I am processing adult glioma image T1-CE, T1, T2,FLAIR,DWI. I use ITKsnap software to check. Below is my original image (my original image was taken to separate the tumor from the brain) and the mask.
|
Beta Was this translation helpful? Give feedback.
-
Oh, by the way Sir, the other thing is that when I use the Z-score method to process the image, there are also negative numbers in the pixels.
|
Beta Was this translation helpful? Give feedback.
-
It seems that when you reply in an email, the images aren't attached. Can you add them to this thread on GitHub? Something is strange about your images. 97% of the image is zero which is unusually high. Please check these images to make sure they're reasonable, and make sure the mask aligns with the entire brain (not the tumor). I suspect there are two issues here: 1) Your masks aren't covering the entire brain or are otherwise misaligned, in one or several of the images in the list of images you're using to fit the method. And 2) your images are strange and don't fit the assumptions of the methods in this package. Note that for Nyul, all images used to fit the method need to be of the same contrast (e.g., MPRAGE only). The fit Also, contrast-enhanced images aren't well-supported in this package, so if you're images are contrast-enhanced (likely for gliomas) that may be the issue. In which case, I'd recommend Z-score. See the README for a discussion about this issue. Z-score normalization will output negative numbers, and that's supposed to happen. See the documentation for a description of how the method performs normalization. Nyul shouldn't have many negative values, but—if I recall correctly—it may output a few negative values. If you're sure the images and masks are reasonable (I seriously doubt that given the 97% figure you reported, and the fact that there are many, many zero landmarks which represent the percentiles of the image inside the mask), then I suspect this is a Windows problem. Unfortunately, I can't help with that because I don't have access to a Windows machine. If you're seeing reasonable alignment and images in ITK, please try plotting the images with the masks overlaid with Matplotlib (see their documentation to get started). It could be that ITK is aligning the images by orientation and Hope this helps. If this does turn out to be a legitimate bug in this package, please open up a bug report in the Issues section of the GitHub repo and fully-answer all relevant questions presented in the bug report template. |
Beta Was this translation helpful? Give feedback.
-
Sir, your guess is right. This time I am attaching my pictures
There are very few negative values in the red area, and all negative values in the black area. From what you have just said, my mask and image are wrong, right? The original image must be the whole brain.
I did not process the different sequences of images together.
The other question I have is with this mask and the original image, can I use the Z-score method? Because it would take a long time to make a mask of the whole brain.
If I could, I could finish my graduation thesis as soon as possible.
|
Beta Was this translation helpful? Give feedback.
-
Oh, by the way, the negative values of the black and red areas I just said are after image normalization, there are no negative values on the original image. The black area is 0 on the original image.
|
Beta Was this translation helpful? Give feedback.
-
As I mentioned before, you need to use the GitHub website to write a message that contains photos. Your photos aren't uploaded if you use email. Given than I cannot see the problem and it doesn't appear that you've read the documentation, I'm going to drop off this discussion. Please re-read my responses above, read the documentation, and make sure that you have actual brain masks (e.g., from ROBEX) for the images and the brain masks are registered (aligned) to the brain in the respective images. If you encounter an actual bug, please open an issue and fully complete the bug report form (otherwise I'll close it). I don't have the time to provide general guidance about medical image analysis, so please look to your mentors, peers, and online resources to learn about the relevant methods. I will only respond to issues directly relevant to this package (i.e., a genuine bug on Linux/Mac or a very-clearly pinpointed area where documentation needs to be improved). Best of luck. |
Beta Was this translation helpful? Give feedback.
It seems that when you reply in an email, the images aren't attached. Can you add them to this thread on GitHub?
Something is strange about your images. 97% of the image is zero which is unusually high. Please check these images to make sure they're reasonable, and make sure the mask aligns with the entire brain (not the tumor).
I suspect there are two issues here: 1) Your masks aren't covering the entire brain or are otherwise misaligned, in one or several of the images in the list of images you're using to fit the method. And 2) your images are strange and don't fit the assumptions of the methods in this package.
Note that for Nyul, all images used to fit the method need to be of the sa…