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

Thread: QImage::scaled cause "raster"/"grid"

  1. #1
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default QPainter::drawImage has "grid" if the QImage size is big then widget

    Hello, every body ..
    I am using Qt-4.6 to implement a camera application, that capture preview and the camera output on windows PC / linux PC,

    I capture the camera raw RBG output from USB in a thread, then convert it to RGB888 format and store it in a QImage in another thread,
    after that I use QPainter::drawImage to draw on a QWidget for previewing. if the camera resolution is not fit with the widget size, then the image would be scaled to the widget size i think.

    As your see in the attached photos, the preview image seems fill with "grid", but if I directly save the QImageinto a jpeg file, and watch it with a photo view tool, then it seems ok.


    the camera output resolution is 864*600, and
    1.jpg -- preview in a small widget,
    2.jpg --- preview in a small widget, but large the previews one.
    3.jpg --- the widget size is equal to the camera resolution.

    How to fix this ?

    or is there a better way to go ?

    /WX
    Attached Images Attached Images
    • File Type: jpg 2.jpg (38.6 KB, 44 views)
    • File Type: jpg 1.jpg (46.6 KB, 36 views)
    • File Type: jpg 3.jpg (54.3 KB, 32 views)
    Last edited by wesley; 28th January 2010 at 07:36.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QPainter::drawImage has "grid" if the QImage size is big then widget

    I think this effect is caused by interference of the thin lines (raster) in the background of this image. Try capturing something with a solid (white?) background and see if the problem persists.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QPainter::drawImage has "grid" if the QImage size is big then widget

    Quote Originally Posted by wysota View Post
    I think this effect is caused by interference of the thin lines (raster) in the background of this image. Try capturing something with a solid (white?) background and see if the problem persists.
    the paper you saw in the attached images is already a whilte A4 paper with some black texts.

    /WX

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QPainter::drawImage has "grid" if the QImage size is big then widget

    But I can see a grid on every one of those three pictures. I don't think scaling QImage would cause this.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QPainter::drawImage has "grid" if the QImage size is big then widget

    Quote Originally Posted by wysota View Post
    But I can see a grid on every one of those three pictures. I don't think scaling QImage would cause this.
    Thanks for reply.

    see the new attached photos come with this reply,

    11.jpg -- the camera resolution is 2592*1944, I capture a frame and then QImage::save() to save it into 11.jpg, the image resolution is not scaled,
    12.jpg -- the camera resolution is 2592*1944, use QImage::scaled() to scale the resolution to 400*300, then save it into 12.jpg

    21.jpg -- the camera resolution is 864*600, I capture a frame and then QImage::save() save it into 21.jpg, the image resolution is not scaled,
    22.jpg -- the camera resolution is 864*600, use QImage::scaled() to scale the resolution to 400*300, then save it into 22.jpg

    as you see, the 12.jpg and 22.jpg is filled with "grid", but the 11.jpg and 21.jpg seems ok.


    /WX
    Attached Images Attached Images
    Last edited by wesley; 29th January 2010 at 04:53.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QPainter::drawImage has "grid" if the QImage size is big then widget

    Could you post the exact code that reveals the problem?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QPainter::drawImage has "grid" if the QImage size is big then widget

    Quote Originally Posted by wysota View Post
    Could you post the exact code that reveals the problem?
    Qt Code:
    1. QString photoName = QDateTime::currentDateTime().toString("yyyyMMddhhmmss");
    2. photoName.append(".jpeg");
    3. QImage photo(photoData, photoSize.width(), photoSize.height(), QImage::Format_RGB888);
    4. photo = photo.scaled(800, 600); // with or without this line
    5. photo.save(photoName);
    To copy to clipboard, switch view to plain text mode 
    Last edited by wesley; 1st February 2010 at 09:19.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QPainter::drawImage has "grid" if the QImage size is big then widget

    What if you save the image not as jpeg but as png or bmp?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QPainter::drawImage has "grid" if the QImage size is big then widget

    It seems caused by QImage::scaled(), which used by QPainter::drawImage() internally,

    I tried the way described in this url http://labs.qt.nokia.com/blogs/2009/...mbnail-preview, the result image seems more better.

    Am i right ?

    /WX

  10. #10
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QPainter::drawImage has "grid" if the QImage size is big then widget

    Quote Originally Posted by wysota View Post
    I think this effect is caused by interference of the thin lines (raster) in the background of this image. Try capturing something with a solid (white?) background and see if the problem persists.

    hi guy, have a look at the attached image, it is a screen shot, it seems that this problem is caused by QPainter::drawImage,

    but i am not sure what is going on .
    Attached Images Attached Images

  11. #11
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default QPainter::drawImage caused some "grid"/"raster", if image size is larger than widget

    hello, guy

    I am using Qt-4.6.2 to implement a camera application on win xp profession sp2,

    I capture the camera stream, then construct a QImage, then draw it on a widget use QPainter,

    Qt Code:
    1. painter->drawImage(targetRect, image);
    To copy to clipboard, switch view to plain text mode 

    if I adjust the widget size to fit the image size, it seems ok,
    but if the wiget size is smaller than image size, there are some "grid/raster" on the widget.

    Have a look at the attached photos,

    the 1 image: it is a screen shot, the widget size fit the image size,
    the 2 image: it is a screen shot, the widget size is smaller than the image size.

    NOTE: it adjust some YUV properties of the image, to make the "grid/raster" more easier to see, i am sure that this problem isn't caused by my YUV adjust routines.

    thanks.

    /WX
    Attached Images Attached Images
    Last edited by wesley; 16th April 2010 at 11:14.

  12. #12
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default QImage::scaled cause "raster"/"grid"

    Hello, guys, please have at look at below code that i used to scaled a image.
    Qt Code:
    1. QImage image("0.bmp");
    2. //image = image.scaled(QSize(442, 332), Qt::KeepAspectRatio, Qt::FastTransformation);
    3. image = image.scaled(QSize(442, 332));
    4. image.save("1.bmp");
    To copy to clipboard, switch view to plain text mode 

    There are some "raster"/"grid" at the bottom of the the result image "1.bmp".

    see the attached images for more details.

    0.bmp is grabbed from a camera running on "916x688" resolution, convert to QImage::Image_RGB888, and then save as "bmp" format.

    Thanks

    /WX
    Attached Images Attached Images
    • File Type: jpg 0.jpg (10.1 KB, 12 views)
    • File Type: jpg 1.jpg (10.5 KB, 14 views)

  13. #13
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage::scaled cause "raster"/"grid"

    what if you use SmoothTransformation? what if you scale your image to exactly 1/2, 1/4 of original resolution? what if you scale other image than captured with your camera?
    can you attach the original image?

  14. #14
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QImage::scaled cause "raster"/"grid"

    Quote Originally Posted by faldżip View Post
    what if you use SmoothTransformation? what if you scale your image to exactly 1/2, 1/4 of original resolution? what if you scale other image than captured with your camera?
    can you attach the original image?
    1. the "SmoothTransformation" seems more better, but still has the "raster"

    2. scale to 1/2 it is ok, i don't know why!

    3. scale other image is ok!

    4. the 0.jpg/0.bmp(no matter jpg or bmp format) is the original on the captured from my camera.

    and I also tried "CImg", a open source image library, which has the ability to scale image, the problem still be there.

    So, i think this problem is not caused by QImage::scale, but dued to my camera setup or the routine convert raw data to RGB888, below is the convert routine, please have a look , tell me if something wrong.
    Qt Code:
    1. int Bayer_GRBG_To_RGB888(const uint8_t *src, uint8_t *dst, int width, int height)
    2. {
    3. assert(src != NULL);
    4. assert(dst != NULL);
    5.  
    6. const uint8_t *pSrcRow = src;
    7. uint8_t *pDstRow = dst;
    8. const uint8_t *pSrcRowNext = 0;
    9. const uint8_t *pSrcRowPrev = 0;
    10. long nSrcBytesPerRow = 1 * width;
    11. long nDstBytesPerRow = 3 * width;
    12. long nSrcWidth = width;
    13. long nSrcHeight = height;
    14.  
    15. for (long nRow=0; nRow < nSrcHeight; nRow++) {
    16. pSrcRowNext = pSrcRow + nSrcBytesPerRow;
    17. if (nRow == 0) pSrcRowPrev = pSrcRowNext;
    18. else pSrcRowPrev = pSrcRow - nSrcBytesPerRow;
    19.  
    20. if (nRow == nSrcHeight-1) pSrcRowNext = pSrcRowPrev;
    21.  
    22. for (long nCol = 0, k = 0; nCol < nSrcWidth; nCol++,k += 3) {
    23. long nColNext = nCol + 1;
    24. long nColPrev = nCol - 1;
    25. if (nCol == 0) nColPrev = nColNext;
    26. if (nCol == nSrcWidth-1) nColNext = nColPrev;
    27.  
    28. if ((nRow % 2) == 0) { // even row
    29. if ((nCol % 2) == 0) { // even column, Raw Green
    30. pDstRow[k] = ((long)pSrcRow[nColNext] + pSrcRow[nColPrev]) / 2; // Red
    31. pDstRow[k + 1] = pSrcRow[nCol]; // green
    32. pDstRow[k + 2] = ((long)pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 2; // blue
    33. } else { // odd column, Raw Red
    34. pDstRow[k] = pSrcRow[nCol]; // Red
    35. pDstRow[k + 1] = ((long)pSrcRow[nColPrev] + pSrcRow[nColNext] + pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 4; // Green
    36. pDstRow[k + 2] = ((long)pSrcRowNext[nColNext] + pSrcRowNext[nColPrev] + pSrcRowPrev[nColNext] + pSrcRowPrev[nColPrev]) / 4; // blue
    37. }
    38. } else { // odd row
    39. if ((nCol % 2) == 0) { // even column, Raw Blue
    40. pDstRow[k] = ((long)pSrcRowNext[nColNext] + pSrcRowNext[nColPrev] + pSrcRowPrev[nColNext] + pSrcRowPrev[nColPrev]) / 4; // Red
    41. pDstRow[k + 1] = ((long)pSrcRow[nColPrev] + pSrcRow[nColNext] + pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 4; // Green
    42. pDstRow[k + 2] = pSrcRow[nCol]; // blue
    43. } else { // odd column, Raw Green
    44. pDstRow[k] = ((long)pSrcRowNext[nCol] + pSrcRowPrev[nCol]) / 2; // Red
    45. pDstRow[k + 1] = pSrcRow[nCol]; // Green
    46. pDstRow[k + 2] = ((long)pSrcRow[nColNext] + pSrcRow[nColPrev]) / 2; // blue
    47. }
    48. }
    49. }
    50.  
    51. pSrcRow += nSrcBytesPerRow;
    52. pDstRow += nDstBytesPerRow;
    53. }
    54.  
    55. return 0;
    56. }
    To copy to clipboard, switch view to plain text mode 

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QImage::scaled cause "raster"/"grid"

    Please don't start multiple threads on the same subject. Threads merged.

  16. #16
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage::scaled cause "raster"/"grid"

    So the problem is your camera :]
    The most important part of image processing is image acquisition. Even the best algorithms can't help you if the image quality is poor. And I don't mean only resolution, but also colors, lights which means generaly a quality of the whole scene you make a picture of. Next thing is that the light sensitive matrix (or how the hell is it called in english) in your camera is not the one that will give you the quality you want (generally those megapixels are some kind of cheat because 1 pixel can measure only 1 color (red, gree, blue) so to have color pixels camera needs 2x2 square where it takes 2 green pixels, 1 red, 1 blue and uses interpolation to get RGB values of each pixel).

    So what you can do is a technique which was advised on Qt Labs: if you want to scale some image to for example a little bit less than 1/2 of original resolution, then scale it to 1/2 (which is fast and nice for an obvous reasons :] - take every second row and then every second pixel in thise rows) with a fast transformation and then use smooth transformation to get the final ratio.

  17. #17
    Join Date
    May 2008
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage::scaled cause "raster"/"grid"

    I you scale down an image without smoothing you may have aliasing (see image processing theory) and the grid I see on images makes me think you have aliasing !
    The more your original image has noise, the more aliasing could be a problem. Try to smooth (filter) the image before scaling.

  18. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QImage::scaled cause "raster"/"grid"

    Quote Originally Posted by ness View Post
    I you scale down an image without smoothing you may have aliasing (see image processing theory) and the grid I see on images makes me think you have aliasing !
    The more your original image has noise, the more aliasing could be a problem. Try to smooth (filter) the image before scaling.
    I don't think so. Aliasing can only occur in diagonal directions. What we see here looks more like interlace or something like that. If you scale by 1/2, 1/4, etc. the interlace will go away because all the "interlaced" lines will be discarded. Where the interlace-like effect comes from? I have no idea, probably the data aquisition process was incorrect (format conversion can be treated as part of the aquisition as well). If QImage::scaled() was not working, the effect would be noticable on the whole area of the photo and not only in some special conditions.

  19. #19
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage::scaled cause "raster"/"grid"

    o... didn't check your previous code but I see thats the thing I mentioned above with those cameras :] but didn't think you have to do it by yourself ;]

  20. #20
    Join Date
    Feb 2008
    Posts
    49
    Thanks
    2
    Thanked 4 Times in 1 Post

    Default Re: QImage::scaled cause "raster"/"grid"

    this problem is true for my other camera chips, like ov5620 which producted by OV ..
    Last edited by wesley; 20th April 2010 at 11:02.

Similar Threads

  1. Replies: 3
    Last Post: 8th July 2008, 20:37
  2. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05
  3. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 16:58

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.