I think that if we talk about an image, each one of us will see it by his way, don’t you?. So this image, you can see it as a scene with some objects (book, glasses …) but in reality, this image is some pixels combined and each pixel has a value between 0 and 255:
0 means very dark and 255 means very bright
What is a pixel?
The pixel is an electronic component that is similar to an LED if we are talking about the RGB images because as we know for the colors there are 3 basic colors that we mix to have any color we want.
So here if we take this image and we see its values, you will see that we have a 3D matrix which means we have 3 channels, the first one is for the red color, the second is for the green, and the last one for the blue so when we mixe these three channels we will have an RGB image like our example.
If we talk about a pixel, the idea is very easy. Imagine with me you have a watercolor to paint on white paper as we know using only the three basic colors we can get any color we want, so if you want to paint something you will take these three colors and by mixing them and adding water you will have the color that you want for your draw.
So we need more colors and now it comes to the idea of the watercolors, we said that to have any colors we need to mixe between the three basic colors that make any secondary color, and if we want to control its brightness we can add water to make it more bright or we let it dry to have a dark color.
The RGB image
I think that now you can imagine with me what is an image, don’t you? if we said that a pixel which is a little square that can give us any color we want depending on which basic color we need and the luminance value. So the image is a set of these squares, if we put them together here we have an image. If we take an image using the camera, our smartphone, or any way to make an image now here we are talking about filling these pixels.
this subject is another thing about how do the sensors work to extract the colors from the light … but that’s it.
Now after knowing the basic idea about what is an image, you can understand some information that we hear every day, for example in TVs we see that there are LED screens and LCD screens… I think that you get it! an LED TV means that the pixels of its screen are made by a type of LED and for the LCD, we didn’t talk about it but it’s something different it’s made by some liquids… We don’t need it for the moment because our subject is the image, not the displays.
The monochrome image
I know that a lot of you will ask me why I didn’t start with the monochrome image. Because it is very easy it is the basic image and it has been created before the RGB image. But my idea is to talk about the more popular type of images so that we can have real examples about it and now you will see that the monochrome image is very easy.
So the monochrome images are the white and black images, which means the old images with one channel. You remember that for the RGB images we said that we have 3 channels and each channel is responsible for color, now in the monochrome images we have only one channel but in this case, it is neither a red color nor green nor blue but it contains the mean of the three colors which mean in each pixel we have the mean of the red, green and blue value.
Now it up to you how to do that (if you are interested to do it by your self), so for that, I will use MATLAB which the easiest one for image processing, and here is the result that we will get:
If you are interested and you want to try it by yourself using MATLAB so here is the code:
def prepare_dicoms(dcm_file, show=False): dicom_file_data = pydicom.dcmread(dcm_file).pixel_array HOUNSFIELD_MAX = np.max(dicom_file_data) HOUNSFIELD_MIN = np.min(dicom_file_data) HOUNSFIELD_RANGE = HOUNSFIELD_MAX - HOUNSFIELD_MIN dicom_file_data[dicom_file_data < HOUNDSFILD_MIN] = HOUNSFIELD_MIN dicom_file_data[dicom_file_data > HOUNSFIELD_MAX] = HOUNSFIELD_MAX normalized_image = (dicom_file_data - HOUNS_MIN) / HOUNSFIELD_RANGE uint8_image = np.uint8(normalized*255) opencv_image = cv2.cvtColor(uint8_image, cv2.COLOR_GRAY2BGR) if show: cv2_imshow(opencv_image) # for Google Colab return opencv_image