OpenCV create tiff with altimetry info - c++

Is it possible to create a tiff image with some other band of, for instance, floats, using OpenCV or some similar lib?
I want to store the RGB data along with a parallel channel for some float value for every pixel. Is this possible?

Related

Read DICOM in C++ and convert to OpenCV

I would like to read DICOM images in C++ and manipulate them using opencv.
I managed to read a dicom image using DCMTK however, I am unsure how to convert it to an opencv Mat.
The following is what I have so far:
DicomImage DCM_image("test.dcm");
cv::Mat image(int(DCM_image.getWidth()), int(DCM_image.getHeight()), CV_8U, (uchar*)DCM_image.getOutputData(8));
which results in the following:
In a DICOM viewer, it looks as follows:
After normalising, the grayed image appears as follows:
Any help would be greatly appreciated.
The main problem I can see now is the difference of pixel value ranges (depths).
AFAIK, DICOM can have a rather big depth (16 bit), and you are trying to fit in into CV_8U, which is only 8 bit. You can get DicomImage instance's depth using DicomImage::getDepth(), and then create a cv::Mat with appropriate depth to hold your image data.
You may also need to normalize the data to maximally utilize you available range, so that the display with cv::imshow() would look as expected.
So:
Do DicomImage::getDepth() on your DCM_image
Create a cv::Mat with sufficient depth to hold your data
Scale, if necessary
Before calling DicomImage::getOutputData() on a monochrome DICOM image, you should make sure that you've selected an appropriate VOI transformation (e.g. Window Center & Width). This could be done by DicomImage::setMinMaxWindow(), DicomImage::setWindow() etc. See documentation of the DicomImage class.
Please note, however, that DicomImage::getOutputData() always returns rendered pixel data, i.e. not the original Pixel Data that is stored in the DICOM dataset.
U need to read the data type in DICOM image encoding an convert that to opencv type Mat. The opencv docs provides the entire information on their Mat header.

How to create a 16-bit Video with cv::Mat

I would like to know is there any way to record 16bit depth image as video in opencv or other library? As my project need depth image which is 16bit per pixel, I need to record a sequence of raw depth image pixel data.
Is there any way or alternative to achieve this idea?
Currently, I'm using opencv 2.4.11 in c++
Thanks
After some research, I decided to record as ONI file and extract frame from ONI.

Converting pointcloud2 data to opencv image

I am trying to convert data obtained from a 2D laser scanner into an openCV image. On searching online for this, I found that first I had to convert the laserscan data to pointcloud2, then the pointcloud2 to a ROS image and then the ROS image to an opencv image.
Currently, I do not have access to a lidar, so I had created a node that publishes fake pointcloud2 data. However, I did not understand what organised pointcloud means. I arbitrarily set the height and width parameters to 100 each, and also assigned arbitrary RGB values to points, and I got a 100x100 image, but I do not understand how that image is a representation of my pointcloud data.
Can someone please explain it?
I guess you are using OpenCV and PCL to develop ROS under ubuntu, for pcl::PointCloud2 is ROS point cloud format.
Organised pointcloud difinition:http://pointclouds.org/documentation/tutorials/basic_structures.php#basic-structures
I did some task on point cloud and OpenCV image and always convert point cloud to OpenCV Mat. So I can give you some suggestions.
My develop environment is PCL1.7.2, OpenCV2.4.9, Kinect v2, VS2012 under win8.1. I want to convert project point cloud onto the ground plane and transfer it into an 2D image (OpenCV Mat), you can check my another solution here and here.

Reading Depth map using OpenGL

I have extracted the depth map of 2 images and stored them as .tif file
now I would like to use openGL to join these two images depending on their depth
so I want to read the depth for each image from the .tif file and then use that depth to draw the pixel with the higher depth
to make it more clear the depth map are two images like this
link
so say I have the pervious image and I want to join it with this image
link
my question is how to read this depth from the .tif file
Ok, I'll have a go ;-)
I see the images are just grayscale, so if the "depth" information is just the intensity of the pixel, "joining" them may be just a matter of adding the pixels. This is generally referred to as "blending", but I don't know what else you could mean.
So, you need to;
Read the 2 images into memory
For each pixel (assuming both images the same size):
read the intensity from image A[row,col]
read the intensity from image B[row,col]
write max(A[row,col],B[row,col]) to C[row,col]
Save image C - this is your new "joined" image.
Now OpenGL doesn't have any built-in support for loading/saving images, so you'll need to find a 3rd party library, like FreeImage or similar.
So, that's a lot of work. I wonder if you really want an OpenGL solution or are just assuming OpenGL would be good for graphics work. If the algorithm above is really what you want, you could do it in something like C# in a matter of minutes. It has built-in support for loading (some formats) of image file, and accessing pixels using the Bitmap class. And since your created this images yourself, you may not be bound the the TIFF format.

reading indexed palette image in C++

My platform is Windows. I didn't expect reading indexed palette image to be this difficult in C++. In case you are not familiar with it, it's single channel image but expresses its pixel color with 256 indexed colors called palette.
I was using OpenCV but its imread just converts the file to a 3 channel image so I have no way to save it back to indexed palette image or compare it with another indexed palette image.
I tried to use Bitmap but for some reason, it does not read correct pixel values.
So right now, I am looking for a light library or code to read pixels from indexed palette file.
Using OpenCV to read or write a image from real cameras will lose and change the image information, so I prefer to use gdi+, which is more powerful in dealing with image format problems to solve your problem.
As comments on the question shows, I decided to have two methods, OpenCV for non-indexed-palette images and Bitmap (GDI+) for indexed palette images. Now everything is working perfect.