Search code examples
matlabimage-processingcomputer-visionedge-detection

detecting object in Homogeneous Intensity image


I have image of Tiger's Pugmark (footprint impression) in mud. I want to detect the boundary of the pugmark but the image is uniform in intensity that is foreground and background cannot be distinguished based on intensity variations. What can i do to distinguish between the pugmark and the background.!

tiger's pugmark


Solution

  • In segmentation tasks if you have both

    1. Good markers; and
    2. Strong edges around the object of interest

    then it is directly solved by a Watershed Transform. The problem, of course, is obtaining these markers, as well enhancing relevant edges as needed. Obtaining these might involve problem-specific knowledge, which I don't have for your problem.

    Nevertheless, there are some general methods that might be useful. For instance, connected operators from Mathematical Morphology serve as a way to merge and extend flat zones. Thus, maybe it can give us relatively good markers for the problem. In the following image a morphological reconstruction by opening (a kind of connected operator) was performed in the grayscale version of the original image (left image), and the remaining regional maximum is shown at right.

    enter image description here enter image description here

    Now, we can obtain the morphological gradient of the left image above. We can also do hole filling and a dilation with a small disk in the right image above to obtain more smooth contours -- this defines our marker image. Then, applying a Watershed Transform in the gradient image using our marker image, and then expanding (erode or dilate, depends on how you see it) the watershed lines, we get the following image:

    enter image description here

    I suspect that you can discard too large and too small regions easily. Then, if you have some rough expected sizes for the claws, as well for the palm, you can discard the irrelevant regions. At this point it is only a matter of dilating the areas to form a single component and show the resulting contour in the original image:

    enter image description here

    Sample code for performing each step (the relevant steps are also shown in commented Matlab code):

    f = Import["http://imageshack.us/a/img407/4636/p1060993g.jpg"]
    g = ColorConvert[f, "Grayscale"]                           (* g = rgb2gray(f); *)
    (* First image shown: *)
    geo = GeodesicOpening[g, DiskMatrix[5]]  (* geo = imreconstruct(imerode(g, ... *)
                                             (*         strel('disk', 6)), g);     *)
    (* Second image shown: *)
    marker = MaxDetect[geo]                        (* marker = imregionalmax(geo); *)
    
    (* Watershed on gradient with markers. *)
    mgrad = ImageSubtract[Dilation[geo, 1], Erosion[geo, 1]]; (* mgrad = ...       *)
              (* imdilate(geo,strel('square',3)) - imerode(geo,strel('square',3)); *)
    ws = Image[           (* ws = watershed(imimposemin(mgrad, bwmorph(imfill(...  *)
     WatershedComponents[mgrad,      (* imregionalmax(geo),'holes'),'dilate'))));  *)
      Dilation[FillingTransform[marker], DiskMatrix[1]]]]
    
    (* Third image shown: *)
    wsthick = Erosion[ws // ImageAdjust, DiskMatrix[5]]
    
    (* Connected component selection based on some supposed sizes. *)
    ccs = SelectComponents[wsthick, "Count", 1000 < # < 3000 || 6000 < # < 10000 &]
    
    (* Final image (thick border on binarized filled dilated ccs) *)
    res = ImageAdd[f, Dilation[MorphologicalPerimeter[FillingTransform[
         MorphologicalPerimeter[Dilation[ccs, DiskMatrix[9]]]]], 2]]