Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Display 2D array of type double* as image
Forum Updated to NodeBB v4.3 + New Features

Display 2D array of type double* as image

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hei6775
    wrote on 29 Jan 2021, 07:38 last edited by
    #1

    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.

    J 1 Reply Last reply 29 Jan 2021, 07:43
    0
    • H hei6775
      29 Jan 2021, 07:38

      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.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 29 Jan 2021, 07:43 last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      H 1 Reply Last reply 29 Jan 2021, 08:43
      3
      • J jsulm
        29 Jan 2021, 07:43

        @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.

        H Offline
        H Offline
        hei6775
        wrote on 29 Jan 2021, 08:43 last edited by
        #3

        @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.

        J J 2 Replies Last reply 29 Jan 2021, 08:49
        0
        • H hei6775
          29 Jan 2021, 08:43

          @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.

          J Offline
          J Offline
          JonB
          wrote on 29 Jan 2021, 08:49 last edited by JonB
          #4

          @hei6775
          I don't know of an image format (supported by Qt, at least) which takes any doubles as an image format. Indeed, we don't know what that format actually is.

          If you need to convert an array of doubles to, say, an array of ints, declare the int array with the same dimensions as the double array and iterate through every double value converting it to int 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.

          1 Reply Last reply
          0
          • H hei6775
            29 Jan 2021, 08:43

            @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.

            J Offline
            J Offline
            jsulm
            Lifetime Qt Champion
            wrote on 29 Jan 2021, 12:00 last edited by
            #5

            @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.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            H 1 Reply Last reply 29 Jan 2021, 12:23
            2
            • J jsulm
              29 Jan 2021, 12:00

              @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.

              H Offline
              H Offline
              hei6775
              wrote on 29 Jan 2021, 12:23 last edited by
              #6

              @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.

              J 1 Reply Last reply 29 Jan 2021, 12:27
              0
              • H hei6775
                29 Jan 2021, 12:23

                @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.

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 29 Jan 2021, 12:27 last edited by
                #7

                @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?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                H 1 Reply Last reply 29 Jan 2021, 12:35
                1
                • J jsulm
                  29 Jan 2021, 12:27

                  @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?

                  H Offline
                  H Offline
                  hei6775
                  wrote on 29 Jan 2021, 12:35 last edited by
                  #8

                  @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

                  J 1 Reply Last reply 29 Jan 2021, 12:38
                  0
                  • H hei6775
                    29 Jan 2021, 12:35

                    @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

                    J Offline
                    J Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on 29 Jan 2021, 12:38 last edited by
                    #9

                    @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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    H 1 Reply Last reply 29 Jan 2021, 12:47
                    2
                    • J jsulm
                      29 Jan 2021, 12:38

                      @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.

                      H Offline
                      H Offline
                      hei6775
                      wrote on 29 Jan 2021, 12:47 last edited by
                      #10

                      @jsulm Hahaha, I want to know if there is a better way to show it. If there has to be a loss of accuracy, there is no problem.

                      1 Reply Last reply
                      0
                      • Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on 29 Jan 2021, 12:49 last edited by
                        #11

                        Then take a look at QImage::Format_Grayscale8/16 QImage format and convert your data to this.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        3

                        1/11

                        29 Jan 2021, 07:38

                        • Login

                        • Login or register to search.
                        1 out of 11
                        • First post
                          1/11
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved