Display 2D array of type double* as image
-
wrote on 29 Jan 2021, 07:38 last edited by
I have a pointer to my image pixel values represented as double data type. I want to display it as a image in Qt. Is the QImage::QImage suitable for this task? If yes, how can I convert double * to uchar * ? Moreover, how to show image? I tried all the provided maps but no one displays it well.
-
I have a pointer to my image pixel values represented as double data type. I want to display it as a image in Qt. Is the QImage::QImage suitable for this task? If yes, how can I convert double * to uchar * ? Moreover, how to show image? I tried all the provided maps but no one displays it well.
@hei6775 What image format is that?
You would use https://doc.qt.io/qt-5/qimage.html#fromData to load binary data as image, but you have to know what format that is. Here is a list of supported formats: https://doc.qt.io/qt-5/qimagereader.html#supportedImageFormats
If your format is not supported you will have to convert the data to a supported format first. -
@hei6775 What image format is that?
You would use https://doc.qt.io/qt-5/qimage.html#fromData to load binary data as image, but you have to know what format that is. Here is a list of supported formats: https://doc.qt.io/qt-5/qimagereader.html#supportedImageFormats
If your format is not supported you will have to convert the data to a supported format first.wrote on 29 Jan 2021, 08:43 last edited by@jsulm hi, the data's format is double in C++. I am doing something about simulation. I will create 2D matrix of double. The double type is 8-byte, right?
I don't know how to deal with the convertion.
I am new to Qt and C++ in general.
-
@jsulm hi, the data's format is double in C++. I am doing something about simulation. I will create 2D matrix of double. The double type is 8-byte, right?
I don't know how to deal with the convertion.
I am new to Qt and C++ in general.
wrote on 29 Jan 2021, 08:49 last edited by JonB@hei6775
I don't know of an image format (supported by Qt, at least) which takes anydouble
s as an image format. Indeed, we don't know what that format actually is.If you need to convert an array of
double
s to, say, an array ofint
s, declare theint
array with the same dimensions as the double array and iterate through everydouble
value converting it toint
in the new array.I don't know whether a library like boost might contain a function to do this any faster than this. Be aware that if you have "large" images/you need to do this repeatedly I would think this could be a "slow" operation.
-
@jsulm hi, the data's format is double in C++. I am doing something about simulation. I will create 2D matrix of double. The double type is 8-byte, right?
I don't know how to deal with the convertion.
I am new to Qt and C++ in general.
@hei6775 said in Display 2D array of type double* as image:
the data's format is double in C++
How is this data interpreted? One double per pixel? One double per base color (RGB), so 3 doubles per pixel? You have to know this if you want to use such images.
-
@hei6775 said in Display 2D array of type double* as image:
the data's format is double in C++
How is this data interpreted? One double per pixel? One double per base color (RGB), so 3 doubles per pixel? You have to know this if you want to use such images.
-
@jsulm one double per pixel. It seems that QT can't handle data of type double. Even if double is converted to a supported type, it will cause a lack of precision.
@hei6775 And how exactly does such a double represent a pixel? I mean, how is the color encoded? Do you actually have an exact format specification?
-
@hei6775 And how exactly does such a double represent a pixel? I mean, how is the color encoded? Do you actually have an exact format specification?
-
@jsulm The data is like a grayscale image, and the value of each pixel is represented by a double type. For example, if the first pixel value is 198.88, then the double value is 198.88
@hei6775 Do you really need such a precision? I mean displays have anyway limited capabilities, so I don't see why loosing some precition when converting to another (supported) format for displaying the picture would be a problem.
-
@hei6775 Do you really need such a precision? I mean displays have anyway limited capabilities, so I don't see why loosing some precition when converting to another (supported) format for displaying the picture would be a problem.
-
Then take a look at QImage::Format_Grayscale8/16 QImage format and convert your data to this.
1/11