<p>It looks like your image will always have the same black area due to the mechanism used to take the picture. If that's the case then you don't need to detect the edges. Instead, you can create a static mask ahead of time. The mask can be a single channel image that's white where the eye image is and black elsewhere. You can use that 1 channel mask as the alpha mask for the RGB image you have.</p>

<p>If the image can move around, it looks to me that you could threshold the red channel and say any red value under 0.1, say, is outside of the eye. Another possibility is just let the user select a circular region for the big circle, and then let them select a smaller one for the bump.</p>

<p>To expand the ROI once you've got the mask, you can go pixel by pixel and if the mask is black, follow the vector from the current pixel towards the center of the image until you hit a non-black pixel. When you hit one, just copy that pixel to the one you started with. Do that with each pixel that's not in the eye portion of the image.</p>

<p><strong>EDIT</strong>: Given that the mask is static there's an even easier way. In <a href="https://computergraphics.stackexchange.com/questions/9196/how-to-create-static-alpha-masks-of-an-image">your other question</a> I pointed out that the center of the larger circle was at approximately (279, 283.5) and its radius was approximately 265. So what you could do is simply iterate over all the pixels in the image and if they're farther than 265 pixels away from the center, replace them with the pixel that is 265 pixels away from the center in the same direction. Something like this untested pseudocode:</p>

<pre><code>float centerX = 279;
float centerY = 283.5;
float radius = 265;
for (int row = 0; row &lt; MAX_ROWS; row++)
{
    for (int col = 0; col &lt; MAX_COLS; col++)
    {
        float deltaX = col - centerX;
        float deltaY = row - centerY;
        float dist = sqrt(deltaX * deltaX + deltaY * deltaY);
        if (dist &gt; radius)
        {
            float dirX = deltaX / dist;
            float dirY = delatY / dist;
            float edgeX = centerX + radius * dirX;
            float edgeY = centerY + radius * dirY;
            SetPixel(col, row, GetPixel(edgeX, edgeY));
        }
    }
}
</code></pre>

<p>Note that the smaller circle presents another issue. You can test whether a given pixel is in the big circle as above, and if not, then see what the distance to the smaller circle is. If that distance is smaller than the distance to the larger circle, then get the pixel from the smaller circle rather than the larger one.</p>

CC BY-SA 4.0
2019-09-29T13:05:24.283Z
Thanks a lot. Yes, my images have a same black area. I searched alot but couldn't find how to create the static mask.Could you help me out?
Mark
CC BY-SA 4.0
2019-09-29T17:06:15.207Z
You can use my suggestion above. Take one image into a photo editor such as Photoshop or Gimp, use the threshold tool to turn everything where the red channel is < 0.1 to black and everything else to white. You may need to adjust the threshold a little, but you want to be conservative. You don't want to have any partially-colored/partially-black pixels showing up as white in your mask. You may need to do a little clean-up by hand.
user1118321
CC BY-SA 4.0
2019-09-30T13:14:01.137Z
Applied but still couldn't wrap my head around how to expand it, how to go radially inwards in an image, and even if I managed to done it, it'll expand the alpha mask not the image.
Mark
CC BY-SA 4.0
2019-10-01T01:19:18.760Z
I've updated my answer to provide another way to expand the ROI that should be pretty clear.
user1118321
CC BY-SA 4.0
2019-10-01T12:51:37.960Z
The issue with this approach is we need to replace the boundary pixel (outside the FOV) with mean value of its neighbourhood(eight-neighbourhood) and here we are just copying the pixels to the boundary pixels.
Mark
CC BY-SA 4.0
2019-10-01T14:02:31.330Z
Here, I added a new question with my issues https://stackoverflow.com/questions/58186472/artificially-increasing-the-region-of-interest-of-an-image
Mark
CC BY-SA 4.0
2019-10-02T15:11:36.890Z
okay, I have got it but I have another follow-up doubt, as all the operations we are doing are on the alpha mask, how to move them from alpha mask to the original required image
Mark
CC BY-SA 4.0
2019-09-28T02:39:55.920Z
2019-10-01T01:19:02.713Z
2019-10-01T01:19:02.713Z
user1118321
<p>I am solving an image segmentation problem. To increase the accuracy of the model, I came across the following preprocessing step-</p>
<blockquote>
<p>First, the set of pixels of the exterior border of the ROI is de-
termined, i.e., pixels that are outside the ROI and are neighbors
(using four-neighborhood) to pixels inside it. Then, each pixel value
of this set is replaced with the mean value of its neighbors (this
time using eight-neighborhood) inside the ROI. Finally, the ROI is
expanded by inclusion of this altered set of pixels. This process is
repeated and can be seen as artificially increasing the ROI.</p>
</blockquote>
<p>The image after applying the following algorithm is below-
<a href="https://i.sstatic.net/jgBZe.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/jgBZe.png" alt="enter image description here" /></a></p>
<p>Can anyone please help me how to approach this problem, I am pretty much clue-less how to do it, how to detect the boundary of the image.My image is of the following type-
<a href="https://i.sstatic.net/sbVhg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sbVhg.png" alt="enter image description here" /></a></p>
<p>Any help in solving this kind of problem is highly appreciated.</p>

CC BY-SA 4.0
2019-09-27T16:36:18.720Z
Use any edge detection algorithm.
lightxbulb
CC BY-SA 4.0
2019-09-27T16:38:39.293Z
I am using hough transform but the thing is it don't capture the tiny nudge present in my image. Also, could you please tell me how to proceed further
Mark
CC BY-SA 4.0
2019-09-27T16:42:01.607Z
You detect the boundary through an edge detection algorithm. Either use the gradient magnitude, the laplacian, or something more complex (for example canny edge detector).
lightxbulb
<image-processing><image>
Artificially increase the region of interest of an image
Mark
# Artificially increase the region of interest of an image

(Asked by: username_0 on 2019-09-27)

I am solving an image segmentation problem. To increase the accuracy of the model, I came across the following preprocessing step-

> First, the set of pixels of the exterior border of the ROI is de-
> termined, i.e., pixels that are outside the ROI and are neighbors
> (using four-neighborhood) to pixels inside it. Then, each pixel value
> of this set is replaced with the mean value of its neighbors (this
> time using eight-neighborhood) inside the ROI. Finally, the ROI is
> expanded by inclusion of this altered set of pixels. This process is
> repeated and can be seen as artificially increasing the ROI.

The image after applying the following algorithm is below-
[![enter image description here](https://i.sstatic.net/jgBZe.png)](https://i.sstatic.net/jgBZe.png)

Can anyone please help me how to approach this problem, I am pretty much clue-less how to do it, how to detect the boundary of the image.My image is of the following type-
[![enter image description here](https://i.sstatic.net/sbVhg.png)](https://i.sstatic.net/sbVhg.png)

Any help in solving this kind of problem is highly appreciated.

**Tags:** image-processing, image

> **Comments:**
> **username_1**: Use any edge detection algorithm.  
> **username_0**: I am using hough transform but the thing is it don't capture the tiny nudge present in my image. Also, could you please tell me how to proceed further  
> **username_1**: You detect the boundary through an edge detection algorithm. Either use the gradient magnitude, the laplacian, or something more complex (for example canny edge detector).  

---

## 1 answers

### Answer by username_2 on 2019-09-28. Score: 1 | Accepted answer

It looks like your image will always have the same black area due to the mechanism used to take the picture. If that's the case then you don't need to detect the edges. Instead, you can create a static mask ahead of time. The mask can be a single channel image that's white where the eye image is and black elsewhere. You can use that 1 channel mask as the alpha mask for the RGB image you have.

If the image can move around, it looks to me that you could threshold the red channel and say any red value under 0.1, say, is outside of the eye. Another possibility is just let the user select a circular region for the big circle, and then let them select a smaller one for the bump.

To expand the ROI once you've got the mask, you can go pixel by pixel and if the mask is black, follow the vector from the current pixel towards the center of the image until you hit a non-black pixel. When you hit one, just copy that pixel to the one you started with. Do that with each pixel that's not in the eye portion of the image.

**EDIT**: Given that the mask is static there's an even easier way. In [your other question](https://computergraphics.stackexchange.com/questions/9196/how-to-create-static-alpha-masks-of-an-image) I pointed out that the center of the larger circle was at approximately (279, 283.5) and its radius was approximately 265. So what you could do is simply iterate over all the pixels in the image and if they're farther than 265 pixels away from the center, replace them with the pixel that is 265 pixels away from the center in the same direction. Something like this untested pseudocode:

```
float centerX = 279;
float centerY = 283.5;
float radius = 265;
for (int row = 0; row < MAX_ROWS; row++)
{
    for (int col = 0; col < MAX_COLS; col++)
    {
        float deltaX = col - centerX;
        float deltaY = row - centerY;
        float dist = sqrt(deltaX * deltaX + deltaY * deltaY);
        if (dist > radius)
        {
            float dirX = deltaX / dist;
            float dirY = delatY / dist;
            float edgeX = centerX + radius * dirX;
            float edgeY = centerY + radius * dirY;
            SetPixel(col, row, GetPixel(edgeX, edgeY));
        }
    }
}

```

Note that the smaller circle presents another issue. You can test whether a given pixel is in the big circle as above, and if not, then see what the distance to the smaller circle is. If that distance is smaller than the distance to the larger circle, then get the pixel from the smaller circle rather than the larger one.

> **Comments:**
> **username_0**: Thanks a lot. Yes, my images have a same black area. I searched alot but couldn't find how to create the static mask.Could you help me out?  
> **username_2**: You can use my suggestion above. Take one image into a photo editor such as Photoshop or Gimp, use the threshold tool to turn everything where the red channel is < 0.1 to black and everything else to white. You may need to adjust the threshold a little, but you want to be conservative. You don't want to have any partially-colored/partially-black pixels showing up as white in your mask. You may need to do a little clean-up by hand.  
> **username_0**: Applied but still couldn't wrap my head around how to expand it, how to go radially inwards in an image, and even if I managed to done it, it'll expand the alpha mask not the image.  
> **username_2**: I've updated my answer to provide another way to expand the ROI that should be pretty clear.  
> **username_0**: The issue with this approach is we need to replace the boundary pixel (outside the FOV) with mean value of its neighbourhood(eight-neighbourhood) and here we are just copying the pixels to the boundary pixels.  
> **username_0**: Here, I added a new question with my issues https://stackoverflow.com/questions/58186472/artificially-increasing-the-region-of-interest-of-an-image  
> **username_0**: okay, I have got it but I have another follow-up doubt, as all the operations we are doing are on the alpha mask, how to move them from alpha mask to the original required image  

---

