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.
|
|
|
|
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
|
|
|
|
Rank: Newbie
Groups: Guest
Joined: 4/10/2018(UTC) Posts: 5
Thanks: 2 times
|
Sure, here it is
|
|
|
|
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
|
1 user thanked Eugene Kosmin for this useful post.
|
|
|
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?
|
|
|
|
Rank: Advanced Member
Groups: Guest
Joined: 9/19/2006(UTC) Posts: 505
Was thanked: 41 time(s) in 41 post(s)
|
|
Best regards, Eugene Kosmin The Aurigma Development Team
|
1 user thanked Eugene Kosmin for this useful post.
|
|
|
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.
|
|
|
|
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
}
}
}
}
|
|
|
|
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.