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
wolszhang  
#1 Posted : Monday, July 3, 2017 12:33:42 PM(UTC)
wolszhang

Rank: Newbie

Groups: Guest
Joined: 7/3/2017(UTC)
Posts: 1

Thanks: 1 times
I have an indexed bitmap that I need to convert to a black and white (monochrome, not grayscale). How can I apply some custom threshold to it? For example, i want all pixels that are less than some thresholds to be white, others black?
Julia Khoptyan  
#2 Posted : Tuesday, July 4, 2017 2:28:16 AM(UTC)
Julia Khoptyan

Rank: Advanced Member

Groups: Guest
Joined: 8/19/2016(UTC)
Posts: 33

Was thanked: 1 time(s) in 1 post(s)
Hi Wolszhang,

You can implement this as follows:

Code:

//Setting desired threshold
int threshold = 170;
Aurigma.GraphicsMill.Bitmap bitmap = new Aurigma.GraphicsMill.Bitmap(@"input.jpg");
for(int i = 0; i < bitmap.Palette.Count; i++)
{
     // RGB-to-brightness calculation taken from https://stackoverflow.com/a/596243
     var brightness = (0.299 * bitmap.Palette[i].R + 0.587 * bitmap.Palette[i].G + 0.114 * bitmap.Palette[i].B);
     if (brightness > threshold)
     {
          bitmap.Palette[i] = Aurigma.GraphicsMill.RgbColor.White;
     }
     else
     {
          bitmap.Palette[i] = Aurigma.GraphicsMill.RgbColor.Black;
     }
}
bitmap.ColorManagement.Convert(PixelFormat.Format1bppIndexed);
bitmap.Save(@"output.tif"); 

Best regards,

Julia

thanks 1 user thanked Julia Khoptyan for this useful post.
wolszhang on 7/5/2017(UTC)
daniel12  
#3 Posted : Saturday, July 29, 2017 1:30:50 AM(UTC)
daniel12

Rank: Newbie

Groups: Guest
Joined: 7/29/2017(UTC)
Posts: 1

Hi,

I also indexed bitmap that I need to convert to a black and white and want all pixels that are less than some thresholds to be black.I implemented the code as shown below,but it does not work well.What can I do for this and how can I fix the issue?

Thanks!

Edited by moderator Sunday, July 30, 2017 9:28:19 PM(UTC)  | Reason: no external site links are allowed here!

Andrey Semenov  
#4 Posted : Sunday, July 30, 2017 9:46:15 PM(UTC)
Andrey Semenov

Rank: Advanced Member

Groups: Guest
Joined: 7/4/2017(UTC)
Posts: 43

Was thanked: 12 time(s) in 12 post(s)
Hi daniel12,

Please post your code that doesn't work and we will take a look. Could you also add some details on the issue?

Regards,

Andrew

Edited by user Sunday, July 30, 2017 9:47:55 PM(UTC)  | Reason: Not specified

Fedor  
#5 Posted : Monday, July 31, 2017 8:52:41 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 post an image you would like to convert?
Best regards,

Fedor Skvortsov

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.