# How can I implement a region splitting and merging technique for image segmentation?

Consider an image (img) as There are six different textures in the image and I want to segment them using region splitting and merging. The property that I wish to consider (feel free to recommend alternatives) is: mean - variance or MeanEuclideanDistance.

How can I proceed?

• You should know what parameters and their values used in each image partition to split and then merge. – José Antonio Díaz Navas Jan 23 '18 at 18:51
• @JoséAntonioDíazNavas I know this. you may choose any random parameter and its values for splitting and merging. I am willing to have a framework to start with. – Majis Jan 23 '18 at 19:11
• Is "region splitting and merging technique" the name of an algorithm or does it mean that you want to take the image apart and then put it together again? – C. E. Jan 24 '18 at 5:36
• @C.E. "Region splitting and merging" is a standard technique for image segmentation. See this link (users.cs.cf.ac.uk/Dave.Marshall/Vision_lecture/node34.html). – Majis Jan 24 '18 at 8:21
• @C.E. The question is updated. Thanks. – Majis Jan 24 '18 at 9:20

img = Import["D:\\Tmp\\test.jpg"]
id = ImageData[img]; It is evident, that simple parameter that allows distinguishing of the image segments here is something like Variance or StandardDeviation of pixel intensity. Let's try to scan image with Variance:

yt = Variance /@ id[[All, All, 1]];
xt = Variance /@ Transpose@id[[All, All, 1]];

st = {Joined -> True, ImageSize -> 300, PlotRange -> All};
Row@{
ListPlot[xt, st],
ListPlot[yt, st]
} Thus, just look for thresholds:

xd = {}; yd = {};
Do[
If[Abs[xt[[i + 1]] - xt[[i]]] > 0.6*xt[[i]], AppendTo[xd, i]],
{i, 2, Length@xt - 1}]
Do[
If[Abs[yt[[i + 1]] - yt[[i]]] > 0.6 yt[[i]], AppendTo[yd, i]],
{i, 2, Length@yt - 1}]

{xd, yd}


{{225}, {150, 300}}

ImagePartition[img, {xd, yd[]}] // Grid I would first partition the image by using a UI to limit regions. Then, perform a weighted Kalman filter for each region.

You can then apply the filter data to each part of the image resizing until the AI finds 'trusted' areas. From this uncertainty can be unblocked by using smaller regions against the filter data until every pixel is accounted for.

Also, I would suggest that if this is one frame in a movie, you now know the relative coordinates for each region so can apply each 1 frame forward and also 1 frame back. This way the relative neighbours form the overall matrix for the image, not the image object boundaries.

• Can you provide a Mathematica code? – Kuba Jan 27 '18 at 21:40