Ask Your Question

Elric's profile - activity

2020-02-23 00:24:38 -0600 asked a question Mask an image with another image

Mask an image with another image I'm newbie with Python and OpenCV. I have two Numpy Array, both with the same shape (2

2020-02-10 08:35:38 -0600 asked a question Highlight areas with different colour that the area that surround them

Highlight areas with different colour that the area that surround them I've just started with Computer Vision and also w

2020-01-29 09:20:06 -0600 received badge  Supporter (source)
2020-01-29 09:19:46 -0600 commented answer Convert a 2D Numpy array to CV_8UC1 type

As easy as that. Thanks a lot!

2020-01-29 09:19:14 -0600 marked best answer Convert a 2D Numpy array to CV_8UC1 type

I'm newbie with Python and Numpy.

I have read a DICOM file (*.nii.gz) into a Numpy array with the following code:

import SimpleITK as sitk
flair_file = '/content/gdrive/My Drive/Colab Notebooks/.../FLAIR.nii.gz'

images = sitk.ReadImage(flair_file)
print("Width: ", images.GetWidth())
print("Height:", images.GetHeight())
print("Depth: ", images.GetDepth())

print("Dimension:", images.GetDimension())
print("Pixel ID: ", images.GetPixelIDValue())
print("Pixel ID Type:", images.GetPixelIDTypeAsString())

It shows this output:

Width:  240
Height: 240
Depth:  48
Dimension: 3
Pixel ID:  8
Pixel ID Type: 32-bit float

And then, I convert them into a Numpy array:

images_array = sitk.GetArrayFromImage(images)
print(np.amin(images_array),np.amax(images_array))

print(images_array[24].shape, images_array[24].dtype)

With this output:

0.0 2380.6191
(240, 240) float32

I have found that I can convert it to CV_8UC1 OpenCV type, but I don't know how.

I want to convert it because I want to use it with the cv2.equalizeHist method.

What do I have to do to convert it to CV_8UC1 type?

The DICOM file has this information:

Title: FLAIR.nii.gz
Width:  230.0000 mm (240)
Height:  230.0000 mm (240)
Depth:  144.0000 mm (48)
Size:  11MB
X Resolution:  1.0435 pixels per mm
Y Resolution:  1.0435 pixels per mm
Voxel size: 0.9583x0.9583x3.0000 mm^3
ID: -2
Bits per pixel: 32 (float)
Display range: 0 - 1980.8942
Image: 1/48
No threshold
ScaleToFit: false
Uncalibrated
Path: /FLAIR.nii.gz
Screen location: 927,131 (1920x1080)
Coordinate origin:  0,0,0
No overlay
No selection
2020-01-29 09:19:14 -0600 received badge  Scholar (source)
2020-01-29 08:52:29 -0600 asked a question Convert a 2D Numpy array to CV_8UC1 type

Convert a 2D Numpy array to CV_8UC1 type I'm newbie with Python and Numpy. I have read a DICOM file (*.nii.gz) into a N