Reputation: 399
Tried to rotate my lung CT 3d scan images using numpy.rot90
or skimage.transform.rotate
, the images contain only the region of interest of lung means it contains some white dots with a black background, the rotation is done like below:
#skimage rotation
rot_img = skimage.transform.rotate(reg_intereset_np_arr1, angle=90, mode='reflect')
#numpy rotation
rot_img = np.rot90(reg_intereset_np_arr1, k=2)
rot_img = np.flipud(reg_intereset_np_arr1)
# reg_intereset_np_arr1 is 3d image (3d scan)
my problem is each of these ways reverses the dots and background colors, makes the image white background with black dots.
the rotation is not only reverses the black and white, but also the content of reversed image is not the same as original image, please tell me how to solve that?
Upvotes: 0
Views: 585
Reputation: 399
The problem of question is two-part, part1 which is the inversion of white and black color and it is solved by above answer, the second part is content changing and solution is: The images are in 3d shape, I tried to rotate the 3d images using numpy or skimage as seen in the question which also changes the image content, but after that, I realized that 3d image cannot be rotated like that, so I rotated the 2d slice of the 3d image, the problem of changing content is solved.
# instead of
rot_img = np.rot90(reg_intereset_np_arr1, k=2) #`reg_intereset_np_arr1` is the 3d image
# the 3d image has 194 slices (2d images)
# and I use
rot_img = np.rot90(reg_intereset_np_arr1[40], k=2) # 40 is one of the 2d images.
Upvotes: 1
Reputation: 2521
You can use rot_img = np.invert(rot_img)
to invert white to black, and vice versa. If your image is in 1
and 0
(in other words, in boolean format), then you could simply use rot_img = ~rot_img
to invert it.
Upvotes: 1