Solved

HTML5 - Canvas - how to find a shape in a canvas and count the number of red pixels

Posted on 2014-10-20
5
152 Views
Last Modified: 2014-10-28
Hi..
Any idea how I can find a shape in a canvas (image) and count the number of pixels of the shape.
Say I have an image with a circle and an a square.
How can I find / or count the number of red pixels the square takes up.
thx in advance
square.png
0
Comment
Question by:JElster
5 Comments
 
LVL 14

Assisted Solution

by:Don Thomson
Don Thomson earned 167 total points
ID: 40391987
If you can determine the dimensions of the square then calculate the number of dquare inches - and from your screen resolution - you should be able to calculate the  number of pixels.  This assumes that all the pixels are red.
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 167 total points
ID: 40392660
If it is your own page, then you put the square in the canvas with scripting and the Object for the square should have height and wisth properties (which may be dynamic) so if you multiple the offsetWidth by the offsetHeight that should give you the total number of pixels based on the current state of the object being rendered as a square.  If you want to know how of a specific colour you would have to script a scan of the rendered area of the object and count the occurrence of the specific value.

If this is from a page you don't control then you might be able to get an approximation by diong a screen shot and counting the pixels in a graphics program.

Cd&
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 166 total points
ID: 40394440
You might also want to consider the definition of "red" since it might mean strictly RGB = 255,0,0 but a visual red could be many variants of the RGB values and still look quite red to the observer.  For example, in the attached image file, the red area contains RGB = 237,28,36.
0
 
LVL 1

Accepted Solution

by:
JElster earned 0 total points
ID: 40400099
0
 
LVL 1

Author Closing Comment

by:JElster
ID: 40408040
best
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now