1
$\begingroup$

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

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

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

$\endgroup$
3
  • $\begingroup$ Use any edge detection algorithm. $\endgroup$
    – lightxbulb
    Sep 27, 2019 at 16:36
  • $\begingroup$ 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 $\endgroup$
    – Mark
    Sep 27, 2019 at 16:38
  • $\begingroup$ 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). $\endgroup$
    – lightxbulb
    Sep 27, 2019 at 16:42

1 Answer 1

1
$\begingroup$

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 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.

$\endgroup$
7
  • $\begingroup$ 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? $\endgroup$
    – Mark
    Sep 29, 2019 at 13:05
  • 1
    $\begingroup$ 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. $\endgroup$ Sep 29, 2019 at 17:06
  • $\begingroup$ 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. $\endgroup$
    – Mark
    Sep 30, 2019 at 13:14
  • $\begingroup$ I've updated my answer to provide another way to expand the ROI that should be pretty clear. $\endgroup$ Oct 1, 2019 at 1:19
  • $\begingroup$ 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. $\endgroup$
    – Mark
    Oct 1, 2019 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.