Y800 image format(s) available in OpenCV - opencv

What is possible image format of Y800 which is available in OpenCV? is it always referred to GRAY? Any other options?
Thanks in advance.

Eight years later, I stumbled upon this question. I want to add an answer with regard to OpenCV 4.2.0.
For videos, this version features an ffmpeg backend which natively understands the FOURCC identifier "Y800". Confusingly, it does not take one-channel grayscale (CV_8UC1) frames, but the usual OpenCV three-channel BGR (CV_8UC3):
cv::VideoWriter vw("y8.avi", cv::VideoWriter::fourcc('Y', '8', '0', '0'), 60, frame.size());
vw.write(frame); // note: frame must be 8UC3!
OpenCV supports the grayscale mode in number of image file formats, including, but not limited to PGM, PNG and JPEG.
cv::imwrite("gray.pgm", image);

Related

Research Paper Implementation (Image Processing)

I'm trying to implement this paper on my own, but there're some parts I don't fully understand.
UIumbra has three channels, since it's the result of multiplication between I and n, where I is an original (color) image.
Q. Step 4 requires a binarization image B1 from UIumbra. It uses an integral image technique for binarization, which is equivalent to OpenCV's adaptiveThreshold. Unfortunately, adaptiveThreshold() takes a grayscale image. Is there any method to convert UIumbra to grayscale or does cv2.cvtCOLOR(UI, COLOR_BGR2GRAY) suffice?
Q. LBWF is a binary version of LWF. LWF takes and returns a grayscale image. How do you make a binary version? (ex. binarize the input?)
The paper doesn't explain those details, so I'm having troubles.
(I did send an email to the author, waiting for the answer. Meanwhile, I want to hear your thoughts)
Any help or idea is appreciated.

Image format in segmentation via neural networks

I am doing segmentation via deep learning in pytorch. My dataset is a .raw/.mhd format ultrasound images.
I want to input my dataset into the system via data loader.
I faced few important questions:
Does changing the format of the dataset to either .png or .jpg make the segmentation inaccurate?(I think I lost some information in this way!)
Which format is less data lossy?
How should I make a dumpy array if I don't convert the original image format, i.e., .raw/.mhd?
How should I load this dataset?
Knowing nothing about raw and mhd formats, I can give partial answers.
Firstly, jpg is lossy and png is not. So, you're surely losing information in jpg. png is lossless for "normal" images - 1, 3 or 4 channel, with 8 bit precision in each (perhaps also 16 bits are also supported, don't quote me on that). I know nothing about ultrasound images, but if they use higher precision than that, even png will be lossy.
Secondly, I don't know what mhd is and what raw means in the context of ultrasound images. That being said, a simple google search reveals some package for reading the former to numpy.
Finally, to load the dataset, you can use the ImageFolder class from torchvision. You need to write a custom function which loads an image given its path (for instance using the package mentioned above) and pass it to the loader keyword argument.

WebP Image size reduce using ImageMagick MagickGetImageBlob

I am facing this strange issue where i am trying to read the blob of WebP Image through MagickReadImageBlob and in the next line i just try to fetch the same blob using MagickGetImageBlob . So, my final blob size reduces strangely. So, can anyone explain this behaviour?
I am using Version: ImageMagick 6.9.8-10 Q16 x86_64 on ubuntu 16.04
So, can anyone explain this behaviour?
The MagickReadImageBlob decodes an image-file buffer into a raster of authenticated pixels.
The MagickGetImageBlob encodes the raster back into an image-file buffer.
WebP format can be either lossy, or lossless, as well as implement different compression techniques during the encoding process. It's more than possible that the encoding routine simply found another way to store the raster than the previous one. Your version of ImageMagick has a quantum depth of 16 (Q16), so the decoding/scaling of WebP's 24-bit Color + 8-bit alpha to Q16 might influence some encoding variations. Try setting MagickSetImageDepth(wand, 8) to see if that helps.

different results when openning an image into numpy array using cv2.imread and PIL.Image.open

I am trying to open an image and turn it into a numpy array.
I have tried:
1) cv2.imread which gives you a numpy array directly
2) and PIL.Image.open then do a numpy.asarray to convert the image object.
Then i realise the resulting array from the same picture is different, please see the attached screenshots.
cv2.imread
PIL.Image.open
I would expect the color channel should always have the same sequence, no matter the package, but I do not seem to be able find any documentation for pillow reagarding this.
Or am I just being silly? Thanks in advance for any suggestion!!!
I don't know anything about PIL but, contrary to just about every other system in the world, OpenCV stores images in BGR order, not RGB. That catches every OpenCV beginner by surprise and it looks like that's the case with your example.
Opencv
image = cv2.imread(image_path, 1)
image_cv = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
Pillow
image_from_pil = Image.open(image_path).convert("RGB")
image_pillow = numpy.array(image_from_pil)
image_np equals image_cv
Notes: While reading a JPEG image, image_np and image_cv may be little different because the libjpeg version may be different in OpenCV and Pillow.
As SSteve and Xin Yang correctly say, the main problem could be that cv2 returns spatial domain (pixels) in BGR color plane, instead of usual RGB. You need to convert the output (reverse the order in channels' axis or use cv2.cvtColor).
Even after the color plane conversion, the output might not be the same. Both PIL and cv2 use libjpeg under the hood, but the outputs of libjpeg do differ for different versions. Read this research paper for reference. Based on my experiments I can say that the libjpeg version used by PIL is unpredictable (differs even on two identical MacBook Pro 2020 M1 using brew and the same Python and PIL version).
If it does matter and you want to have control over which libjpeg/libjpeg-turbo/mozjpeg version is used for compression and decompression, use jpeglib. It is still in beta, but the production release is coming.

Improve image quality

I need to improve image quality, from low quality to high hd quality. I am using OpenCV libraries. I experimented a lot with GaussianBlur(), Laplacian(), transformation functions, filter functions etc, but all I could succeed is to convert image to hd resolution and keep the same quality. Is it possible to do this? Do I need to implement my own algorithm or is there a way how it's done? I will really appreciate any kind of help. Thanks in advance.
I used this link for my reference. It has other interesting filters that you can play with.
If you are using C++:
detailEnhance(Mat src, Mat dst, float sigma_s=10, float sigma_r=0.15f)
If you are using python:
dst = cv2.detailEnhance(src, sigma_s=10, sigma_r=0.15)
The variable 'sigma_s' determines how big the neighbourhood of pixels must be to perform filtering.
The variable 'sigma_r' determines how the different colours within the neighbourhood of pixels will be averaged with each other. Its range is from: 0 - 1. A smaller value means similar colors will be averaged out while different colors remain as they are.
Since you are looking for sharpness in the image, I would suggest you keep the kernel as minimum as possible.
Here is the result I obtained for a sample image:
1. Original image:
2. Sharpened image for lower sigma_r value:
3. Sharpened image for higher sigma_r value:
Check the above mentioned link for more information.
How about applying Super Resolution in OpenCV? A reference article with more details can be found here: https://learnopencv.com/super-resolution-in-opencv/
So basically you will need to have the Python dependency opencv-contrib-python installed, together with a working version of opencv-python.
There are different techniques for the Super Resolution in OpenCV you can choose from, including EDSR, ESPCN, FSRCNN, and LapSRN. Code examples in both Python and C++ have been included in the tutorial article as well for easy reference.
A correction is needed
dst = cv2.detailEnhance(src, sigma_s=10, sigma_r=0.15)
using kernel will give error.
+1 to kris stern answer,
If you are looking for practical implementation of super resolution using pretrained model in OpenCV, have a look at below notebook also video describing details.
https://github.com/pankajr141/experiments/blob/master/Reasoning/ComputerVision/super_resolution_enhancing_image_quality_using_pretrained_models.ipynb
https://www.youtube.com/watch?v=JrWIYWO4bac&list=UUplf_LWNn0a9ubnKCZ-95YQ&index=4
Below is a sample code using opencv
model_pretrained = cv2.dnn_superres.DnnSuperResImpl_create()
# setting up the model initialization
model_pretrained.readModel(filemodel_filepath)
model_pretrained.setModel(modelname, scale)
# prediction or upscaling
img_upscaled = model_pretrained.upsample(img_small)

Resources