0

I am working with software that has a proprietary image format. I need to be able to display a modified version of these images in a QT GUI. There is a method (Image->getpixel(x,y)) that returns a 16 bit integer (16 bits per pixel). To be clear, the 16 bit number does not represent an RGB color format. It literally represents a measurement or dimension to that particular point (height map) on the part that is being photographed. I need to take the range of dimensions (integers) in the image and apply a scale to be represented in colors. Then, I need to use that information to build an image for a QPixmap that can be displayed in a Qlabel. Here is the general gist...

QByteArray Arr;
unsigned int Temp;
for (int N = 0; N < Image->GetWidth(); N++) {
    for (int M = 0; M < Image->GetHeight(); M++) {
        Temp = Image.GetPixel(N,M);
        bytes[0] = (Temp >> 8) & 0xFF;
        bytes[1] = Temp & 0xFF;
        Arr.push_back(bytes[0]);
        Arr.push_back(bytes[1]);
    }
}

// Take the range of 16 bit integers.  Example (14,982 to 16,010)
// Apply a color scheme to the values
// Display the image
QPixmap Image2;
Image2.loadFromData(Arr);
ui->LabelPic->setPixmap(Image2);

Thoughts?

This screenshot is an example of what I am trying to replicate. It is important to note that the coloration of the image is not inherent to the underlying data in the image. It is the result of an application scaling the height values and applying a color scheme to the range of integers. enter image description here

bluebass44
  • 65
  • 1
  • 10

2 Answers2

2

The information on proprietary image format is limited so the below is guess or thought (as requested) according to explanation above:

QImage img(/*raw image data*/ (const uchar*) qbyteArr.data(),
   /*columns*/ width, /*height*/ rows,
   /*bytes per line*/ width * sizeof(uint16),
   /*format*/ QImage::Format_RGB16); // the format is likely matching the request

QPixpam pixmap(img);                 // if the pixmap is needed
Alexander V
  • 8,351
  • 4
  • 38
  • 47
  • I am aware of this method, but my real issue is how to get the data from a 16 bit unsigned int to a const uchar*. I have updated my post with some new code. Let me know what you think. – bluebass44 Jan 13 '17 at 21:51
  • uchar is simply a byte and pointer to it here is a pointer to the head of graphics data buffer. That is why the reinterpret_cast or older C-style cast is there. You may try to point to source buffer and what you do in that code is not descriptable to me as long as I don't know specifics. – Alexander V Jan 13 '17 at 21:53
  • I have updated my post with new information that I am slowly gleaning. You will have to forgive the incomplete information as the documentation is severely lacking. What other information would you like to see? – bluebass44 Jan 15 '17 at 17:53
  • What you show seems to be compatible with the approach I propose. It is important to know how many columns and rows and how many bytes per row (line). Just try not to use the code above first and use that QImage constructor right away. Otherwise, try to explain the format in words. Current explanation makes it compatible with Format_RGB16. Maybe R-G-B in different order but how do I know? – Alexander V Jan 15 '17 at 17:58
  • I am evidently doing a poor job explaining the format. Let me try again like this. The 16 bit integer is a single number. It has no component parts like an R-G-B. It just is a range of integers that only mean something once a scale is applied to them. If I said that for every 1 difference in integer it represents .001". Then the actual height difference between 14380 and 14400 is .020". Does that help? – bluebass44 Jan 15 '17 at 18:18
  • No color info? Black and white with some scale then? What is the brightest and the darkest then? The darkest is 0x000000 and the brightest is a white with 0xFFFFFF of 3 colors? I suggest to repost this question with more detailed explanation of the graphics format that people symply don't know. Anyway, that is not Qt but the spec of your task which is not clear. – Alexander V Jan 16 '17 at 00:07
0

I found pieces of the answer here.

Algorithm to convert any positive integer to an RGB value

As for the actual format, I chose to convert the 16 bit integer into a QImage::Format_RGB888 to create a heat map. This was accomplished by applying a scale to the range of integers and using the scale to plot different color equations.

Community
  • 1
  • 1
bluebass44
  • 65
  • 1
  • 10