Solved

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

Posted on 2014-10-20
5
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 110

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

730 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