Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Tuesday, May 23, 2006 2:06:57 AM(UTC)
im_umer_rasheed

Groups: Registered
Posts: 2


Hi
I need to count no of pixel of a specific color in an image. is there any method for this?

Regards,
Umer Rasheed

 

 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Wednesday, May 24, 2006 5:35:27 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

You can do this by setting adding a region that consists of all pixels of a specified color, and then get the area of this region.
The details depend on the programming interface that you use.
For example, if you are using LEADTOOLS OCX programming interface, you can add the region using the LEAD1.SetRgnColor method. And then you can get the region are using the LEAD1.GetRgnArea.
The code will be something as following:
+--------------------------------------+
Dim Area As Long
LEAD1.Load "c:\red1.jpg", 0, 0, 1
LEAD1.RgnFrameType = RGNFRAME_ANIMATED
LEAD1.SetRgnColor RGB(255, 0, 0), L_RGN_SET
Area = LEAD1.GetRgnArea
MsgBox Area
+--------------------------------------+

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
#3 Posted : Monday, May 29, 2006 9:09:47 PM(UTC)
im_umer_rasheed

Groups: Registered
Posts: 2


Thanks for helping

Can you tell me how to do this in .Net version. Also i need to know total no of pixels, so i can measure what is the percentage of a specific color in an image.

Regards,
Umer Rasheed

 

 
#4 Posted : Wednesday, May 31, 2006 3:37:08 AM(UTC)
Maen Hasan

Groups: Registered, Tech Support
Posts: 1,326

Was thanked: 1 time(s) in 1 post(s)

Hello,

To get the pixel count for a specific color in the image, you need to create a region that contains this color using the IRasterImage.AddColorToRegion Method. Then you need to calculate the pixel count using the IRasterImage.CalculateRegionArea Method. The code will be soothing as follows:
+--------------------+
Dim LeadImage As IRasterImage
Dim codecs As RasterCodecs
codecs = New RasterCodecs
LeadImage = codecs.Load("c:\red1.jpg")
LeadImage.AddColorToRegion(New RasterColor(Color.Yellow), RasterRegionCombineMode.Set)
MessageBox.Show("The pixel count =" + LeadImage.CalculateRegionArea().ToString())
+--------------------+

Now, you can calculate the pixel count for the image by using the IRasterImage.CalculateRegionArea Method without defining any regions.

Thanks,
Maen Badwan
LEADTOOLS Technical Support
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.080 seconds.