# Surface and length

**URL:** https://discourse.processing.org/t/surface-and-length/25394
**Category:** Coding Questions
**Tags:** homework
**Created:** [November 13, 2020, 12:08pm UTC](https://discourse.processing.org/t/surface-and-length/25394 "2020-11-13T12:08:35Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ala](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@ala](https://discourse.processing.org/u/ala)
#### Post date: [November 13, 2020, 12:08pm UTC](https://discourse.processing.org/t/surface-and-length/25394/1 "2020-11-13T12:08:35Z")

</div>

Hello,  
I have a problem. I have to write a program for designating the area and length of the edge of a color spot at the click of a mouse. I know that i must load a picture and and that the actions are after a click, but i don’t know how get the surface and edge length. Do you have an idea?

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [November 13, 2020, 1:55pm UTC](https://discourse.processing.org/t/surface-and-length/25394/2 "2020-11-13T13:55:55Z")

</div>

> [@ala](#):
>
> for designating the area and length of the edge of a color spot

Hi @ala  
Can you explain this part in more detail?  
What do you mean by edge of a color spot?

---

<div class="post-metadata">

### Author: ![ala](https://avatars.discourse-cdn.com/v4/letter/a/a8b319/32.png) [@ala](https://discourse.processing.org/u/ala)
#### Post date: [November 14, 2020, 6:52pm UTC](https://discourse.processing.org/t/surface-and-length/25394/3 "2020-11-14T18:52:44Z")

</div>

so i have something like this and i must get a surface and length of edge this “spot” (circuit?) after clicking the mouse on it.

 ![Bez tytułu](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b681f2f93dd0dbabff6f4d7b7c333aae0aae2e4a.png)

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [November 14, 2020, 7:21pm UTC](https://discourse.processing.org/t/surface-and-length/25394/4 "2020-11-14T19:21:08Z")

</div>

I still don’t understand what you mean.  
If you want to calculate the surface area, that would be simple.  
Just count how many red pixels, (or not white), in [the pixel array here.](https://processing.org/reference/pixels.html)  
But what would be the edge? Maybe the rectangle boundary?  
That’s also simple, but you have to keep track of the x and y value of the pixel array, and search for the most upper and left pixel value.  
You can learn about it here:

[![](https://img.youtube.com/vi/j-ZLDEnhT3Q/hqdefault.jpg "10.5: Image Processing with Pixels - Processing Tutorial") ](https://www.youtube.com/watch?v=j-ZLDEnhT3Q)

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [November 14, 2020, 7:27pm UTC](https://discourse.processing.org/t/surface-and-length/25394/5 "2020-11-14T19:27:46Z")

</div>

Hello,

This should help:

> **[Images and Pixels \\ Processing.org](https://processing.org/tutorials/pixels/)**

The area is proportional to the number of red pixels.

You can get the pixel locations along the edge (red to white) and get the distance between these.

I got started with some success but need to get some fresh air and sun before dark.

Think about it and then start coding this; this is a really good exercise!

I won’t be sharing my code here.

Other resources here:

> **[Processing.org](https://processing.org)**

`:)`

---

<div class="post-metadata">

### Author: ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)
#### Post date: [November 14, 2020, 8:09pm UTC](https://discourse.processing.org/t/surface-and-length/25394/6 "2020-11-14T20:09:16Z")

</div>

> [@noel](#):
>
> But what would be the edge? Maybe the rectangle boundary?

Maybe OP is looking for the contour length ?

---

<div class="post-metadata">

### Author: ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)
#### Post date: [November 15, 2020, 6:15am UTC](https://discourse.processing.org/t/surface-and-length/25394/7 "2020-11-15T06:15:43Z")

</div>

> [@solub](#):
>
> Maybe OP is looking for the contour length

Oh yes, probably. It’s in the title.  
Anyway, it’s all about the pixels array. In this case, he should count the number of pixels that have different color neighbors.
