Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
irwan  
#1 Posted : Thursday, February 16, 2006 1:28:16 PM(UTC)
irwan

Rank: Member

Groups: Member
Joined: 2/16/2006(UTC)
Posts: 7

Hi,

I am doing a VB app, that required to count the number of pixel of a certain color code.
Is there a way to use GraphicsMill to do this.

I have managed to used getDIBits, but the process is a bit slow, and when the picture is too big, it will throws an error saying that 'Can't AutoRedraw Image' even when the autoredraw is off.

Thank you, your reply will be much appreciated.
Andrew  
#2 Posted : Friday, February 17, 2006 1:03:59 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Graphics Mill does not implement color counting feature. You can easily implement this feature by iterating through each pixel and comparing it with required color. To speed it up, you can use low-level access as described here Creating Custom Effects topic.

But if you give some additional background information about your application, I could try to suggest some alternative ways to do your task with Graphics Mill. Why you need to calculate number of pixels of some color? Do you need to get the most frequent color or something else?

Edited by user Tuesday, December 15, 2009 10:35:46 AM(UTC)  | Reason: Not specified

irwan  
#3 Posted : Sunday, February 19, 2006 10:20:16 AM(UTC)
irwan

Rank: Member

Groups: Member
Joined: 2/16/2006(UTC)
Posts: 7

Hi Andrew,

Thank you for the reply.
The application was designed so that the user can draw a shape on the drawing screen with a solid color.
Basically what they are drawing is a plan of a house.

So what they do is they picked a color from a pallette for example say green, then draw a shape. this shape can be arbitary. And in order to calculate the area of an arbitary shape, I counted the number of pixel of the green color. Since I know what the scale is say 1px is 1m then once I counted that there is 40 pixels of green color, then it means that there is 40m2 area.

hopefully this gives you a better picture of what the program is doing.

Andrew  
#4 Posted : Monday, February 20, 2006 9:44:58 PM(UTC)
Andrew

Rank: Advanced Member

Groups: Member, Administration
Joined: 8/2/2003(UTC)
Posts: 876

Thanks: 2 times
Was thanked: 27 time(s) in 27 post(s)
Ok, now I understand. However I afraid it is not good way to calculate the area. It will cause accuracy loss if the user will draw diagonal lines.

Consideration that 1 pixel occupies one square meter, valid only if you draw squares (vertical or horizontal lines only). When you draw a diagonal line, its "axis" will divide the pixel. See an attached image for better understanding.

To calculate the square precisely, you should do it on the step when the user draws shape (i.e. when you know its coordinates). In this case you can use some math to calculate the shape area.
Andrew attached the following image(s):
triangles.GIF
Users browsing this topic
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.