Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Using a 2d data array to create an image

  1. #1
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Using a 2d data array to create an image

    Hi

    I am new to Qt and windows types programs in general. I have a 2d array of data (could either be 32bit float or char ). I would like to use this data to create an image to display in a window. I would be grateful if somebody could point me in the right direction

    Best Regards

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    look at this method QImage::fromData or this QPixmap::loadFromData.

  3. #3
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Thanks, but the data is raw just a 2d array of floats (could be chars), it does not have a header. I am really stuck on this. Also how do I display this image in a window, what do I have to do to achieve this (justy the basics)?

    Thanks

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    for displaying an image you can use, for example, QLabel::setPixmap.

    how do you get raw data?

  5. #5
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Thanks spirit.

    The data is loaded from a file into a 2d array. The data represents a memory dump of a Radars B-Plane. We have a algorithm which sharpens up radar displays and I want to create a simulator which shows a 'before' and 'after' image. I am not familar with qt or gui's , so all this talk of widgets etc is a bit confusing at the moment. All i want, as a first attempt is a way to create an image/picture of this data and display it in some window.

    Thanks once again

  6. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    this file where picture is stored has only image data or someother data too?

  7. #7
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Hi

    The file just contains raw data samples obtained using an analog to digital converter

    Thanks

  8. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    how do you know that raw data has correct image? I'm confused.

  9. #9
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Hi

    The data are just samples, each samples amplitude is to represent a pixels intensity in the final image . Essentially all I have is 2d array of data, from which I want to create an image for display. I was looking at QImage as a possible solution, as you can load the QImage buffer with data using scanline, but I couldnt get this to work.

    Thanks

  10. #10
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Hi

    I suppose you could look at the problem this way. Consider a 2d array of chars of say 200 rows x 200 columns. Every element in a row has the same value, this value increases by one for every row. So for example each sample in the first row might have sample value of 1, the second row 2 and so on until we get to the final row which would have sample value of 200. If you created an image of this 2d array you would expect to see horizontal lines of increasing intensity (if we assume a grayscale image). How could I create such an image using QT and display this on a label/widget

    Thanks for your time

  11. #11
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    then use QImage this class allows to access to pixels.

  12. #12
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Yes, I have used QImage and loaded the buffer with my data. How di I subsequently display this QImage on a widget?

  13. #13
    Join Date
    Jul 2008
    Posts
    69
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    I am also looking at similar problem (moving image )

    so in the designer create a Qlabel
    then access Qlabel ui.labelName->setQimage or something like that
    then modify the QImage using QPainter

    then update the

    I found an example in the demo to draw a ball with gradient
    Qt Code:
    1. pixmap = QPixmap(100, 100);
    2. pixmap.fill(Qt::transparent);
    3.  
    4. QRadialGradient gradient(50, 50, 50, 50, 50);
    5. gradient.setColorAt(0, QColor::fromRgbF(1, 0, 0, 1));
    6. gradient.setColorAt(1, QColor::fromRgbF(0, 0, 0, 0));
    7. QPainter painter(&pixmap);
    8. painter.fillRect(0, 0, 100, 100, gradient);
    9.  
    10. channelImage = pixmap.alphaChannel();
    11. update();
    To copy to clipboard, switch view to plain text mode 

    I am not sure yet if we can modify the Qpainter dot by dot
    This may help

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using a 2d data array to create an image

    Quote Originally Posted by dbrmik View Post
    Yes, I have used QImage and loaded the buffer with my data. How di I subsequently display this QImage on a widget?
    Transform it to QPixmap and display using QLabel.

  15. #15
    Join Date
    Jul 2008
    Posts
    69
    Thanks
    9
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Using a 2d data array to create an image

    the problem seems to be how to modify the QPixmap having a set of coordinates X,Y
    is there any good example around?

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using a 2d data array to create an image

    The pixmap is used to display data. QImage is used to manipulate data. Use QImage to change pixel colours and a pixmap created from it to display the image.

  17. #17
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Hi

    I've made a little progress, however I think I need halep with the colour map. I have created an 8bit image and filled all values in each row with a constant.

    QImage BPlaneI(rows,cols,QImage::Format_Indexed8);//8 bit image
    loadImageData(ch_ptr,rows,cols,&BPlaneI);

    Then converted to pixamp and displayed on a label

    QPixmap qp(rows,cols);
    qp.fromImage(BPlaneI,Qt::AutoColor);
    QLabel l;
    l.setPixmap(qp);
    l.show();

    However the label display is entirely black, I have also queried the depth of the pixmap and this shows a depth of 32, I was expecting 8?

    I would be grateful if anybody had any ideas why this might be the case

    Best regards

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using a 2d data array to create an image

    8bit images use a colour look-up table thus the value you put as pixel data is the index in the colour table which is probably empty thus you get all black. QPixmap will always be 32b. Reading documentation really doesn't hurt - try it.

  19. #19
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Thanks wysota, yes RTFM, i've said that in the past

    I assume that the conversion from 8bpp to 32bpp doesnt scale the pixel values and that is why my label is black?

    Do I have to create a colour table, how do I associate the colour table with my pixmap? I am confused.

    Best Regards

  20. #20
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Using a 2d data array to create an image

    Still having problems with this, I have realised I need to create a colortable which I have populated with 'yellow' for all entries, so expecting a yellow image. The image is still black.
    My code is below

    QImage BPlaneI(ch_ptr,rows,cols,QImage::Format_Indexed8);//8 bit image
    BPlaneI.setNumColors(256);
    loadImageData(ch_ptr,rows,cols,&BPlaneI);//load image buffer from ch_ptr

    for (int i=0; i<255; i++)
    {
    BPlaneI.setColor(i,Qt::darkYellow);
    }

    QPixmap qp(rows,cols);
    qp.fromImage(BPlaneI,Qt::AutoColor);

    QLabel l;
    l.setPixmap(qp);
    l.show();

    Really stuck with this one, any ideas would be greatly appreciated

    Thanks

Similar Threads

  1. Replies: 2
    Last Post: 29th September 2008, 00:08
  2. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00
  3. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  4. how to create resource fork & data fork
    By jyoti in forum General Discussion
    Replies: 4
    Last Post: 28th November 2006, 17:20
  5. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.