Page 1 of 1

Unexpected RGB values

Posted: 2014-06-23T06:20:22-07:00
by infoabout
Hi,
I use as test image the following:

Code: Select all

$identify test.jpg
test.jpg JPEG 500x500 500x500+0+0 8-bit sRGB 193KB 0.000u 0:00.000
If I take a look to the first pixels I have:

Code: Select all

$convert test.jpg txt:-
# ImageMagick pixel enumeration: 500,500,255,srgb
0,0: (66,70,82)  #424652  srgb(66,70,82)
1,0: (65,68,83)  #414453  srgb(65,68,83)
2,0: (62,68,82)  #3E4452  srgb(62,68,82)
3,0: (62,70,81)  #3E4651  srgb(62,70,81)
...
The problem is when I try to display the pixels value with the current program:

Code: Select all

    ExceptionInfo
    *exception;
    
    Image
    *origin_image,
    *clone_image;
    
    ImageInfo
    *origin_image_info;
    
    const PixelPacket
    *p;
    
    PixelPacket
    *q;
    
    ssize_t
    x,
    y;
    
    
    origin_image_info = AcquireImageInfo();
    (void) strcpy(origin_image_info->filename, origin_filename);
    exception = AcquireExceptionInfo();
    origin_image = ReadImage(origin_image_info, exception);
    
    if (exception->severity != UndefinedException)
        CatchException(exception);
    if (origin_image == (Image *) NULL)
        MagickFatalError(ResourceLimitError, "Fatal Error", "can't open the image");
    
    clone_image = CloneImage(origin_image, origin_image->columns, origin_image->rows, MagickTrue, exception);
    if (clone_image == (Image *) NULL)
    { /* an exception was thrown */ }

    for (y=0; y < (ssize_t) origin_image->rows; y++)
    {
        p=GetVirtualPixels(origin_image,0,y,origin_image->columns,1,exception);
        q=GetAuthenticPixels(clone_image,0,y,clone_image->columns,1,exception);
        if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL)) break;
        for (x=0; x < (ssize_t) clone_image->columns; x++)
        {
            printf("\n(%d,%d) %d %d %d", x, y, p->red, p->green, p->blue);
            SetPixelRed(q,p->red);
            SetPixelGreen(q,p->green);
            SetPixelBlue(q,p->blue);     
            p++;
            q++;
        }
        
        if (SyncAuthenticPixels(clone_image,exception) == MagickFalse)
            break;
    }
    
    if (y < (ssize_t) clone_image->rows)
    {         MagickFatalError(ResourceLimitError, "Fatal Error", "error"); }
    
    (void) strcpy(clone_image->filename, clone_filename);
    WriteImage(origin_image_info, clone_image);
The program generate the following output:

Code: Select all

(0,0) 16962 17990 21074
(1,0) 16705 17476 21331
(2,0) 15934 17476 21074
(3,0) 15934 17990 20817
...
How can I obtain the simple 8-bit RGB values ?
If now I take a look to the clone_image pixel with the convert utility, I get another difference:

Code: Select all

$convert clone_test.jpg txt:-
# ImageMagick pixel enumeration: 500,500,255,srgb
0,0: (66,70,82)  #424652  srgb(66,70,82)
1,0: (65,68,83)  #414453  srgb(65,68,83)
2,0: (63,69,83)  #3F4553  srgb(63,69,83)
3,0: (62,70,81)  #3E4651  srgb(62,70,81)
...
Why the rgb values at (2,0) are different form the original test.jpg file ?

Thanks for the help

Re: Unexpected RGB values

Posted: 2014-06-23T06:57:45-07:00
by snibgo
You are running 16-bit IM ("Q16"). When this reads 8-bit files, it extends the values by copying the byte. Eg 66 becomes 66*256+66 = 16962.

Sorry, I can't help with your other questions.