This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
conamx  
#1 Posted : Tuesday, April 10, 2018 6:46:33 AM(UTC)
conamx

Rank: Newbie

Groups: Guest
Joined: 4/10/2018(UTC)
Posts: 5

Thanks: 2 times
Hi…

I was able to read 8-bit JPG (24bpp RGB) pixels using C# and the pixel values are in the range of 0-255 which is normal as 2^8=256.

Following is the code I used to access 8 bit image pixel values in C#:

Code:

       for (int x = 0; x < image.width; x++)  
         {       
            for (int y = 0; y < image.height; y++)    
            {           
                     int redValue     = image.GetPixel(x, y).R;      
                     int greenValue = image.GetPixel(x, y).G;  
                     int blueValue   = image.GetPixel(x, y).B;  
                    //Do something with redValue, greenValue, blueValue here
             } 
        }

Please let me know if I can read 16-bit TIFF (48bpp RGB) pixel values using GM and what would be the range of those pixel values.

Thanks.

Fedor  
#2 Posted : Tuesday, April 10, 2018 7:44:53 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Could you attach an example of 48bpp TIFF image?

Edited by user Tuesday, April 10, 2018 9:08:24 AM(UTC)  | Reason: Not specified

Best regards,

Fedor Skvortsov

conamx  
#3 Posted : Tuesday, April 10, 2018 10:25:40 AM(UTC)
conamx

Rank: Newbie

Groups: Guest
Joined: 4/10/2018(UTC)
Posts: 5

Thanks: 2 times
Sure, here it is

Gradient16.png

Eugene Kosmin  
#4 Posted : Tuesday, April 10, 2018 4:25:02 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Guest
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Hi,

Please try the following code.

Code:
using (var bitmap = new Bitmap("48bppRgb.tif"))
{
    var pixel = (Rgb16Color)bitmap.GetPixel(x, y);
    Console.WriteLine(pixel.R);
    Console.WriteLine(pixel.G);
    Console.WriteLine(pixel.B);
}

The range will be [0..65535].

Best regards,

Eugene Kosmin

The Aurigma Development Team

thanks 1 user thanked Eugene Kosmin for this useful post.
conamx on 4/14/2018(UTC)
conamx  
#5 Posted : Tuesday, April 10, 2018 11:35:04 PM(UTC)
conamx

Rank: Newbie

Groups: Guest
Joined: 4/10/2018(UTC)
Posts: 5

Thanks: 2 times
That's good. But the code takes very long time to execute. Is it possible to make code execution faster?
Eugene Kosmin  
#6 Posted : Thursday, April 12, 2018 4:18:44 PM(UTC)
Eugene Kosmin

Rank: Advanced Member

Groups: Guest
Joined: 9/19/2006(UTC)
Posts: 505

Was thanked: 41 time(s) in 41 post(s)
Only with unsafe code. It's faster but requires dealing with data pointer.

Please check this topic about Scan0 property.

Best regards,

Eugene Kosmin

The Aurigma Development Team

thanks 1 user thanked Eugene Kosmin for this useful post.
conamx on 4/14/2018(UTC)
conamx  
#7 Posted : Friday, April 13, 2018 9:44:04 AM(UTC)
conamx

Rank: Newbie

Groups: Guest
Joined: 4/10/2018(UTC)
Posts: 5

Thanks: 2 times
Thank you for the link. The example on the page states that the code is for 8 bit images where each byte is incremented to get next color.

But, I'm not sure how to implement the same example for 48bpp images where two bytes are incremented to get next color.

conamx  
#8 Posted : Saturday, April 14, 2018 11:00:48 AM(UTC)
conamx

Rank: Newbie

Groups: Guest
Joined: 4/10/2018(UTC)
Posts: 5

Thanks: 2 times
Okay, I finally figured it out. Here is the code:

Code:
 using (var bitmap = new Aurigma.GraphicsMill.Bitmap(@"48bpp.tif"))
            {
               unsafe
                {
                      //A pointer to the beginning of the pixel data region
                      byte* pointer = (byte*)(bitmap.Scan0.ToPointer());

                      //Number of bytes in a row
                      ushort stride =(ushort) bitmap.Stride;

                      //Number of rows
                      int height = bitmap.Height;

                      //bytesperpixel
                      int bytesperpixel = bitmap.PixelFormat.Size/8;

                        for (int i = 0; i < height; i++)
                        {
                            ushort* position = (ushort*)(pointer + stride * i);

                            for (int j = 0; j < stride; j = j + bytesperpixel)
                            {
                                double red = position[j + 2];
                                double green = position[j + 1];
                                double blue = position[j];

                                //do something with red green blue

                            }
                        }

                }
            }
Users browsing this topic
Guest (4)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.