7

I have a Dicom file and i would like to apply a number of masks with different operations in the voxels. However, I would like to keep the positions in the initial array because I want to reconstruct the image. This is what I have done:

#The dicom data    
a=dicomm_data.pixel_array
#start function
my_modified_array = np.zeros_like(a)
#mask 1
m1=a[(a>limit_1) & (a<limit_2)]
m1=m1*chosen_number1 + chose_number2
my_modified_array [(a>limit_1) & (a<limit_2)] = m1

#mask 2
m2=a[(a>limit_2+1) & (a<limit_3)]
m2=m1*chosen_number3+chosen_number_4
my_modified_array [(a>limit_2+1) & (a<limit_3)] = m2

and I continue with more masks. However, I am receiving the mentioned in the title error. I have read another post which uses the numpy.where function but still cannot fix it.

3
  • 1
    What is a1? It suddenly appears in an expression without being mentioned before. Commented Nov 3, 2014 at 10:19
  • It is my initial data array. Just correct it. Commented Nov 3, 2014 at 10:21
  • Anyone something to propose? Commented Nov 3, 2014 at 10:50

1 Answer 1

1

You'll get the error when m1 is an empty array but a[(a>limit_2+1) & (a<limit_3)] is not empty. I think

m2=m1*chosen_number3+chosen_number_4

should be

m2=m2*chosen_number3+chosen_number_4

That's the pattern you used with m1, and that would fix the error.

Sign up to request clarification or add additional context in comments.

2 Comments

It worked. Totally my mistake. Thanks. I think I should delete my post.
It happens. If the problem was just a typographical error, then sure, it would make sense to delete the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.