I have some ultrasound images. When I read them using cv.imread and check their shape or check them with ndim, it shows 3 channels:

im = cv.imread(data_path+'a1.jpg')
im = np.array(im)

the output is:
(154, 139, 3)

But when I open them in photoshop and check their mode in Image > Mode, it shows grayscale with 8 bit. Also in windows properties > detail, tab shows 8 bit: enter image description here

Dose anyone have any idea about that?

  • $\begingroup$ what's the format of the image? $\endgroup$ – Alireza Zolanvari Mar 15 '19 at 15:14

What is happening has nothing to do with the type of image (ultrasound in this case). It has to do with the type of file (JPEG in this case). By default, cv.imread assumes it is a 3-channel color image. You can specify grayscale when calling cv.imread if appropriate. The last dimension (the color dimension) in the im object could be empty.

There is also depth info (8 bits per channel). The default is 8 bit, you could specify 16 bit or 32 bit if apporiate.

Do not rely on function or software defaults. It is better to work from first principles of the raw data.

  • $\begingroup$ How can I check if my image is 3 channel or 1 channel? Is there any function to do that? $\endgroup$ – Hunar Mar 15 '19 at 18:37
  • $\begingroup$ simply spoken: gray == 1 channel, everything else 3 $\endgroup$ – Andreas Look Mar 15 '19 at 21:54
  • $\begingroup$ There is high-channel ultrasound that which can have 16, 48, 64, or 256 channels. $\endgroup$ – Brian Spiering Mar 15 '19 at 23:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.