Results 1 to 10 of 10

Thread: QImage pixelIndex resize color Table prolem

  1. #1
    Join Date
    Mar 2018
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Question QImage pixelIndex resize color Table prolem

    Hi everybody.

    Sorry for my language. Please, I have problem, when load image and convert to index format:

    *image = image->convertToFormat( QImage::Format::Format_Indexed8 );

    then reduce color table:

    image->setColorCount( 10 );

    and storage all pixel index to array data:

    for( int posIndex = 0 ; posIndex < 320 * 200 ; posIndex++ )
    {
    int index= image->pixelIndex( posIndex % 320 ,posIndex / 320 );
    image->setPixel( posIndex % 320 ,posIndex / 320 , index /*% colTable.size()*/ );
    data[ posIndex ] = ( char )index;
    }
    Maximum number get from function pixelIndex have be 10, because in color table is 10 items, but I have in array data item above that number 10.

    When check count of items in color Table:

    QVector<QRgb> colTable = image->colorTable();
    cout << "size col table: " << colTable.count() << endl;
    get

    When image put to display:

    item->setPixmap( QPixmap::fromImage( *image ));

    image have correct number of collors. Who is problem? Why function pixelIndex get number above that 10? Is this error of QT?

    Thanks for answer.

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage pixelIndex resize color Table prolem

    Hi,

    I don't understand what you want to do but I think that you are a little bit confused.

    Color Table is a table that contains QRgb values so a Color Table like:

    ColorTable[0] -> (0,0,0) Black
    ColorTable[1] -> (255,255,255) White
    ColorTable[2] -> (255,0,0) Red
    ...

    means that if the pixel value of the image is 1, the output that you will see on the screen is White pixel. If the value of the pixel of the image is 2, the output on the screen will be a Red pixel.

    Do you understand how it works? It's a index table. The image values are INDEXES to the Color Table
    Òscar Llarch i Galán

  3. #3
    Join Date
    Mar 2018
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QImage pixelIndex resize color Table prolem

    Thanks, but I understand how work image with color palette. My problem is other. When I reduce color palette from default 255 items for example to 10:

    image->setColorCount( 10 );

    it will be possible adressing only 10 items in in colorTable:

    index = mage->pixelIndex( x_pos , y_pos ); // index must bee in range 0 to 9

    My problem is, that index is in range 0 to 255, that is wrong. Why index is not in range 0 to 9? Is this bug of QT?

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage pixelIndex resize color Table prolem

    Thanks, but I understand how work image with color palette
    Sure?

    My problem is, that index is in range 0 to 255, that is wrong. Why index is not in range 0 to 9? Is this bug of QT?
    You are assuming that changing the color table of an image will change the pixel values of the image(that are indexes in this case) and it is not true. Changing the color table only changes the color table not the pixel values.

    If you want to change the pixel values(color indexes) you have to change the image pixel values. Do you know what is a LUT(Look Up Table)? An image with a color palette use the color table as LUT for display.
    Òscar Llarch i Galán

  5. #5
    Join Date
    Mar 2018
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QImage pixelIndex resize color Table prolem

    You are assuming that changing the color table of an image will change the pixel values of the image(that are indexes in this case) and it is not true.
    Yes I assumed, that image index change automatic, when change color table. I understand, that color table and pixel index in image is not the same. I assumed, that QT this operation make in background calling inner function.

    An image with a color palette use the color table as LUT for display.
    Just I find how use color table to next conversion:

    imageLoad->setColorCount( 10 );
    QVector<QRgb> colTable;
    colTable = imageLoad->colorTable();
    *imageLoad = imageLoad->convertToFormat( QImage::Format::Format_Indexed8 , colTable );

    , but this have no effect to change index of image. How is possible that? Which functions should I call? Or make I something wrong?
    Last edited by johny333; 8th March 2018 at 13:11.

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage pixelIndex resize color Table prolem

    Hi,

    How would you expect that it will change automatically?

    A RGB Pixel value (230,100,100) wich color table value must have?

    Could you explain us what you are trying to do?
    Òscar Llarch i Galán

  7. #7
    Join Date
    Mar 2018
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QImage pixelIndex resize color Table prolem

    I trying convert image from format, that use full 256 colors to format, that use count color by me. I convert image by my own algorithm. When Image use full 256 index, compress data is for example 1000B. When Image use for example 10 index of colors, compress data is for example 200B. I will have possibility change size of compress data. This is possible when resize count index, that image use.

  8. #8
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QImage pixelIndex resize color Table prolem

    Hi,

    Let's imagine that your image is a 8 bit image. You can create a color table like this:

    Qt Code:
    1. for (int i=0; i<255; i++)
    2. colortable[i] = QRgb(i,i,i);
    To copy to clipboard, switch view to plain text mode 

    Displaying this image you will see a gray scale image.

    Using this color table
    Qt Code:
    1. for (int i=0; i<255; i++)
    2. colortable[i] = QRgb(i,0,0);
    To copy to clipboard, switch view to plain text mode 

    You will see a "red scale" image.

    If you want a color table with only 10 indexes you have to create it as nobody knows wich output colors you expect to get. Finally, from Qt Docs:

    "When the image is used, the color table must be large enough to have entries for all the pixel/index values present in the image, otherwise the results are undefined"

    As your image is still having pixel values higher than 10, the output on the screen is undefined.
    Òscar Llarch i Galán

  9. The following user says thank you to ^NyAw^ for this useful post:

    johny333 (8th March 2018)

  10. #9
    Join Date
    Mar 2018
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QImage pixelIndex resize color Table prolem

    Hi,

    Ok, so is not possible reduce color table and indexes in image. This is answer for my question.

    Thanks.

  11. #10
    Join Date
    Apr 2012
    Location
    Romania
    Posts
    22
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QImage pixelIndex resize color Table prolem

    Hi,

    Not necessarily. You could map all the colours from an image in these 10 colours. For example, you can set colours in the form (i, i, i) which have values between 0 and 100 to be mapped to the colour defined as (50, 50, 50). Something like this:

    Qt Code:
    1. for(int index = 0; index < 255) {
    2. if(index < 100) {
    3. colortable[i] = QRgb(50, 50, 50);
    4. }
    5. if(index >= 100 && index < 255) {
    6. colortable[i] = QRgb(125, 125, 125);
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

    So what you need to do is to decide the RGB values for these 10 colours and map all the shades of these colours to their equivalent in your 10 colours palette. Of course, this will have to be done manually (I mean you decide which shade is equivalent to which colour).

    Best regards,
    Sorin

Similar Threads

  1. Problem with pixelIndex in QImage
    By danilodsp in forum Newbie
    Replies: 2
    Last Post: 17th September 2011, 06:14
  2. QImage::pixelIndex out of range warning
    By danics in forum Qt Programming
    Replies: 1
    Last Post: 10th March 2010, 12:54
  3. color table with QGradient and QImage
    By desch in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2008, 10:32
  4. Replies: 9
    Last Post: 21st June 2007, 10:27
  5. color table for qimage
    By kernel_panic in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2007, 17:44

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.