Results 1 to 15 of 15

Thread: Tiff in unsigned short

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tiff in unsigned short

    Try to set to zero a value of the variable VBLACK.

  2. #2
    Join Date
    Apr 2006
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tiff in unsigned short

    I have updated the code as shown below...
    I can see the full image now but it is rotated anticlockwise 90 degree....
    Any idea why?

    Thanks


    uchar* finalImage = new uchar[300*300];
    _conv16to8bit(image, finalImage, 90000);

    QImage img(300, 300,QImage::Format_Indexed8);
    img.setNumColors(256);
    for(int i = 0; i <= 255; i++)
    {
    int myColor = qRgb(i, i, i);
    img.setColor(i, myColor);
    }

    for(int i = 0; i<300; i++)
    for(int j = 0; j<300; ++j)
    img.setPixel(i, j, finalImage[(i*300)+j]);

    ui.label_Photo->setPixmap( QPixmap::fromImage( img ) );

  3. #3
    Join Date
    Apr 2006
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tiff in unsigned short

    Quote Originally Posted by spawnwj
    for(int i = 0; i<300; i++)
    for(int j = 0; j<300; ++j)
    img.setPixel(i, j, finalImage[(i*300)+j]);
    Hi the image looks fine now. I just swap i and j at setPixel.
    So far so good.
    Thanks for all the help

  4. #4
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tiff in unsigned short

    Quote Originally Posted by spawnwj
    I have updated the code as shown below...
    I can see the full image now but it is rotated anticlockwise 90 degree....
    Any idea why?
    I'm surprised with this behaviour. Do you sure that it happened because of the function of convert?

    I want to explain a bit. This function was made only for display of images, not for processing. This algorithm does scale 16bit values to the 8bit range and considers min and max values of pixels at the same time. If you will processing 8bit image and you need to keep the source image as far as possible you should change the algorithm of convert. It should be such as:
    Qt Code:
    1. template<typename T>
    2. bool conv16to8bit(const T * const data, unsigned char * const dest, unsigned len)
    3. {
    4. if ( !data || !dest || !len ) return false;
    5.  
    6. size_t type_size = sizeof(T);
    7. if ( type_size != 2 ) return false;
    8.  
    9. bool isSigned = ( typeid(T) == typeid(signed short) );
    10.  
    11. T maxValue = ( isSigned ?
    12. static_cast<T>(::pow(2, type_size * 8 - 1)/2)-1 :
    13. static_cast<T>(::pow(2, type_size * 8 - 1)) );
    14.  
    15. unsigned char * dst = dest;
    16. for (const T * pix = data; pix < data+len; pix++)
    17. {
    18. int c = static_cast<int>( 0.5f + (::abs(*pix) / maxValue * 255));
    19. if ( c < 0 ) c = 0;
    20. if ( c > 255 ) c = 255;
    21. *dst++ = static_cast<unsigned char>(c);
    22. }
    23.  
    24. return true;
    25. };
    To copy to clipboard, switch view to plain text mode 

    I didn't check this code. May be it has a couple errors.

  5. #5
    Join Date
    Apr 2006
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tiff in unsigned short

    I have further reduce the code to the one below.
    It looks ok without the rotation issue.

    However I got one question...
    If the source is 16 bit, I got a full image with the right size.
    If the source is 8bit, I got a image that is 1/4 of the size and repeat 2 times.
    For example... The actual full image size is defined below.
    1 2
    3 4
    It will have 2 repeating image on 1 and 2 while 3 and 4 is empty.
    Is this normal?




    uchar* finalImage = new uchar[imageSize.width()*imageSize.height()];
    _conv16to8bit(imageData, finalImage, imageSize.width()*imageSize.height());

    QImage img(finalImage, imageSize.width(), imageSize.height(),QImage::Format_Indexed8);
    img.setNumColors(256);
    for(int i = 0; i <= 255; i++)
    {
    int myColor = qRgb(i, i, i);
    img.setColor(i, myColor);
    }

    Quote Originally Posted by Mad Max
    I'm surprised with this behaviour. Do you sure that it happened because of the function of convert?

    I want to explain a bit. This function was made only for display of images, not for processing. This algorithm does scale 16bit values to the 8bit range and considers min and max values of pixels at the same time. If you will processing 8bit image and you need to keep the source image as far as possible you should change the algorithm of convert. It should be such as:
    Qt Code:
    1. template<typename T>
    2. bool conv16to8bit(const T * const data, unsigned char * const dest, unsigned len)
    3. {
    4. if ( !data || !dest || !len ) return false;
    5.  
    6. size_t type_size = sizeof(T);
    7. if ( type_size != 2 ) return false;
    8.  
    9. bool isSigned = ( typeid(T) == typeid(signed short) );
    10.  
    11. T maxValue = ( isSigned ?
    12. static_cast<T>(::pow(2, type_size * 8 - 1)/2)-1 :
    13. static_cast<T>(::pow(2, type_size * 8 - 1)) );
    14.  
    15. unsigned char * dst = dest;
    16. for (const T * pix = data; pix < data+len; pix++)
    17. {
    18. int c = static_cast<int>( 0.5f + (::abs(*pix) / maxValue * 255));
    19. if ( c < 0 ) c = 0;
    20. if ( c > 255 ) c = 255;
    21. *dst++ = static_cast<unsigned char>(c);
    22. }
    23.  
    24. return true;
    25. };
    To copy to clipboard, switch view to plain text mode 

    I didn't check this code. May be it has a couple errors.

  6. #6
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    50
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tiff in unsigned short

    Quote Originally Posted by spawnwj
    Is this normal?
    Yes, I think this is normal behaviour for this function. I never used it in such way. It seems you've too much oversimplified my function. In original it checks the dimension of source type. Just don't use this function for 8bit images.

  7. #7
    Join Date
    Feb 2006
    Location
    Boulder, Colorado, USA
    Posts
    63
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tiff in unsigned short

    you might want to check out TiffIO as well.

  8. #8
    Join Date
    Apr 2006
    Posts
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Tiff in unsigned short

    Quote Originally Posted by jrideout
    you might want to check out TiffIO as well.
    Thanks... I got that in my system.
    But my source is already converted to ushort*. I can only start working for there.

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
  •  
Qt is a trademark of The Qt Company.