Question

I have this image:

enter image description here

Where the red dots are coordinates that divide the different letters of this Arabic word segment.

I want to detect the dots above or below the areas between the dots.

The dots are (from left to right) = [81,183;80,217;83,275;83,314]

Now there is a dot above the letter between [81,183] and [80,217]. Similarly there are dots above section between [80,217] and [83,275] and dots below region [83,275] and [83,314].

What I want to do is suppose a dot is detected above a coordinate then that coordinate must be deleted. Would it be possible to detect these in Matlab?

edit: Here is the original image

enter image description here

The first image is just a crop showing my region of interest

Was it helpful?

Solution

You can extract the coordinates of the individual objects with regionprops Here is an example implementation:

im=rgb2gray(imread('http://i.stack.imgur.com/jic1X.jpg'));
P=regionprops(~im2bw(im), 'All');

Areas=cell2mat({P.Area});
Centroids=cell2mat({P.Centroid}');

Select only the points that have an area larger that 10 but smaller than 100:

Coord=Centroids(Areas< 100 & Areas > 10,:);

Monitor the dots found:

imshow(im);
hold on
for k=1:length(Coord)
    plot(Coord(k,1), Coord(k,2), 'ro');
    hold on
end

Result:

Dots found

You can then sort the points with something like:

Aboves=Coord(Coord(:,2) < 80,:);
Belows=Coord(Coord(:,2) > 80,:);

From here, there are many ways of solving your problem, one option is the following:

dots=[81,183;80,217;83,275;83,314];

DetectDots=zeros(length(dots)-1, 1); % Creating a vector of zeros corresponding to the gaps between the elements in 'dots' 
for k=1:size(dots,1)-1
    if ~isempty(find((Aboves(:,1) > dots(k,2) & Aboves(:,1) < dots(k+1,2)))) %*
        DetectDots(k)=1;
    elseif ~isempty(find((Belows(:,1) > dots(k,2) & Belows(:,1) < dots(k+1,2))))
        DetectDots(k)=-1;
    else
        DetectDots(k)=0;
    end

end

The result is a vector DetectDots with value [1,1,-1] in this case that indicates that there are dots above between the two first point, and between the second and third point, and dots below between the third and last point of the vector dots.

*find returns a logical array with ones where the condition is met. isempty checks if the output of find has at least one element. As a result the condition is one if there is at least one element in the array Aboves or Belows that meets the criteria. ~ is the logical NOT, hence ~= means not equal. & is the logical AND. Note also that the coordinates between images and arrays are inverted in matlab.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top