0

Please help! I have an image similar to the one attached (a gradient from dark to light moving south to north with a horizontal white line which is of interest) I am trying to look along each vector in the y axis starting from the bottom of the image and locate the bottom of the white line. I could use a sobel-like edge detector but there are dark spots south of the white line..so going into a spot will give my detector a large negative value which I can ignore but as it leaves the dark spot and returns to the gradient I get a large positive value from my detector which I cannot distinguish from the edge where the bottom of the white line is. The code I tried to put together simultaneously grabs the sobel value and intensity at each point and adds to two distinct vectors (the vector with sobel values I use later to locate the max of each y axis vector/bottom edge of white line)..if there's a large negative sobel value (i.e. entering a dark spot) I hold on to the last intensity point prior to start of the spot and use a 'while' to pad the sobel vector with zeros, moving upward until the kernel is safely out of the dark spot (intensity values are greater than prior to entering the dark spot) at which point I start collecting the actual sobel values again. I'm loading an image of height 715 but my sobel vectors are ending up considerably larger than that...not sure what I'm doing wrong:

 for n=1:1:width
     sobVec=[];
     intVec=[];
     for k=height-5:-1:5 
         if (-4*double(J((k+4),n))-3*double(J((k+3),n))-2*double(J((k+2),n))-1*double(J((k+1),n))+0*double(J((k),n))+1*double(J((k-1),n))+2*double(J((k-2),n))+3*double(J((k-3),n))+4*double(J((k-4),n)))>-150
            sobVec(end+1)=-4*double(J((k+4),n))-3*double(J((k+3),n))-2*double(J((k+2),n))-1*double(J((k+1),n))+0*double(J((k),n))+1*double(J((k-1),n))+2*double(J((k-2),n))+3*double(J((k-3),n))+4*double(J((k-4),n));
            intVec(end+1)=J(k,n);
         else
            if isempty(intVec)
                intVec=[1];
            end
            while J((k-1),n)<intVec(end)
                k=k-1;
                sobVec(end+1)=0;          
            end
            if J((k-1),n)>intVec(end)*1.1
                for i=1:1:5
                    k=k-1;
                    sobVec(end+1)=0;
                end
            end 
        end
     end

 end 

enter image description here

Web_Designer
  • 72,308
  • 93
  • 206
  • 262
user3470496
  • 141
  • 7
  • 33

1 Answers1

0

I understand you have a white line, more or less horizontal but with noisy grayvalue pixels in its neighborhood. And your goal is to precisely locate the edge of this white region. The sobel filter is probably not the best approach in this situation, because it is not robust. Instead I would try an order filter, which is part of the Mathlab Image Processing Toolbox (but of course, you can implement this also yourself).

http://ch.mathworks.com/help/images/ref/ordfilt2.html

By experimenting with different neighborhoods (e.g. a vertical line with center at the top) and orders of the filter plus applying a threshold on the result you should be able to find a solution.

Settembrini
  • 1,366
  • 3
  • 20
  • 32