# Box coordinates from image segmentation

**URL:** https://discourse.julialang.org/t/box-coordinates-from-image-segmentation/109987
**Category:** General Usage
**Tags:** images, image-processing, juliaimages, segmentation
**Created:** [February 9, 2024, 3:26pm UTC](https://discourse.julialang.org/t/box-coordinates-from-image-segmentation/109987 "2024-02-09T15:26:00Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![sardinecan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sardinecan/32/29141_2.png) [@sardinecan](https://discourse.julialang.org/u/sardinecan)
#### Post date: [February 10, 2024, 8:44pm UTC](https://discourse.julialang.org/t/box-coordinates-from-image-segmentation/109987/2 "2024-02-10T20:44:32Z")

</div>

I found a solution.  
First, we take the segmentation matrix

```julia
segMap = labels_map(seg)

```

Then, from this matrix, we can retrieve the coordinates of all the pixels in a given segment. Then we can store the X and Y coordinates in two separate variables to finally determine a box around a segment (the black crosses on the image below):

```julia
coordinates = findall(x -> x == 1, segMap)
x = Vector()
y = Vector()

for c in coordinates
    push!(x, c[2])
    push!(y, c[1])
end

xStart = x[1]
xEnd = last(x)

sort!(y)
yStart = y[1]
yEnd = last(y)

```

 ![Capture d’écran 2024-02-10 à 21.11.13](https://global.discourse-cdn.com/julialang/original/3X/5/8/58c78a1cde52f0f7843c1b3aa3a6fbf02471adae.png)

Hope this makes sens!  
Best

---

_[View the full topic](https://discourse.julialang.org/t/box-coordinates-from-image-segmentation/109987)._
