One-dimensional edge detection

Instead of detecting the edges of a 2D image, I would like to detect edges on each individual line (for example, line) of the image separately. This is the detection of edges from the input 1D vector, whose values ​​are pixel intensities in the range from 0 to 255 (image below): enter image description here

I would like to detect the main edges appearing at the input of the sample (image below) enter image description here

+6
source share
3 answers

One way to achieve the desired result is to adapt the two-dimensional Canny detector as follows (code in Mathematica):

First, calculate the spatial derivative using the Gaussian derivative filter by setting the sigma value relative to the scale of the edges you want to detect. Take the absolute value of the result.

d = Abs@GaussianFilter [data, {{10, 5}}, 1]; 

Then, determine the threshold automatically for clustering previous derived values ​​in two groups (the Otsu method is used here).

 thrd = FindThreshold[d]; 

Then determine the steps of the derived values ​​(transitions to / from the "dead zone").

 steps = Flatten@Image `StepDetect[d, thrd]["NonzeroPositions"]; 

At this moment you have the ends of the ribs:

 ListLinePlot[data, Epilog -> {Red, PointSize[Large], Map[Point[{#, data[[#]]}] &, steps]}] 

enter image description here

Optional - it seems that you want to - hold only the lowest ends of the ribs. In this case, clustering data points at the ends of the edges works, but I'm not sure how reliable they are.

 t = FindThreshold@data [[steps]]; steps2 = Select[steps, data[[#]] <= t &]; ListLinePlot[data, Epilog -> {Red, PointSize[Large], Map[Point[{#, data[[#]]}] &, steps2]}] 

enter image description here

+7
source

So, are you looking for a specific change in slope β€” that is, a specific change in Y per pattern?

Is it not easy to look at the difference in Y between two samples, and if this absolute value has changed by more than some limit mark, which is like an edge?

+2
source

Given the good contrast of these edges, there is a simple solution that will work reliably: detect all monotonous sequences of pixel values ​​(strictly increasing or decreasing). You will keep sequences that have a total height above the threshold (50 in your case) to reject noisy peaks.

As a by-product, you will get start and end points (not exactly where you expect them, but you can improve it if necessary).

Barcodes?

+1
source

Source: https://habr.com/ru/post/908355/


All Articles