LEADTOOLS Support
Imaging
Imaging SDK Questions
Count no of pixel of a specific color in an image
This topic and its replies were posted before the current version of LEADTOOLS was released and may no longer be applicable.
#1
Posted
:
Tuesday, May 23, 2006 2:06:57 AM(UTC)
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
#2
Posted
:
Wednesday, May 24, 2006 5:35:27 AM(UTC)
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)
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)
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
LEADTOOLS Support
Imaging
Imaging SDK Questions
Count no of pixel of a specific color in an image
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.