sonidos significa rasguños que escucho escuchar arañazos opencv image-processing computer-vision

opencv - rasguños - que significa escuchar arañazos



Detectando arañazos en la imagen con mucho ruido. (3)

Estoy teniendo problemas para detectar rasguño en estas imágenes. En realidad, es muy fácil de ver por los ojos humanos. Sin embargo, al aplicar algunos algoritmos, hay mucho ruido y no pude extraer el rasguño solamente.

Aquí están estas imágenes:

En la actualidad, probé algunos tipos de filtro (suavizado, promedio, mediana, filtro gaussiano o detector de borde Sobel) para borrar el ruido y detectar rasguños, pero no ayudan mucho. ¿Podría sugerir alguna idea? Algunas herramientas o algoritmos que debo considerar?


Esta es mi implementación para la detección de defectos, es un enfoque muy simple pero efectivo, he implementado este código en MATLAB, pero no es difícil portarlo en ningún idioma porque utiliza operaciones básicas de procesamiento de imágenes.

clc

clear all

close all

  1. Lea Ambas imágenes y muévalas (para un cálculo rápido) por factor de 2.

im1 = imresize(imread(''scratch.jpg''),0.5);

  1. Convertirlos en escala de grises.

gray = rgb2gray(im);

  1. Aplica un filtro gaussiano de tamaño 15 x 15.

gSize = 15;

gray = imfilter(gray,fspecial(''gaussian'',[gSize,gSize],gSize/2),''replicate'');

  1. Findout Gradiente Magnitud de las imágenes utilizando la máscara Sobel.

[~,~,mg,~] = ImageFeatures.Gradients(gray);

  1. Límite de magnitud de gradiente con un umbral de 30 percentiles de valor máximo.

`mgBw = mg> 0.3 * máx (mg (:));

  1. Aplique la operación morfológica Cierre de imagen binaria mediante una máscara de disco de 3 X 3.

mgBw = imclose(mgBw,strel(''disk'',1));

  1. Aplicar análisis de partículas (CCL).

mgBw = bwareaopen(mgBw,500);

  1. Una vez más, cierre la imagen para unir líneas.

mgBw = imclose(mgBw,strel(''disk'',2));

  1. Rellena los agujeros en la imagen.

mgBw = imfill(mgBw,''holes'');

  1. Anotaciones finales:

Prueba el procedimiento anterior en tus imágenes, espero que funcione.

Gracias

Los valores de la máscara gaussiana se indican a continuación. Acabo de copiarlos tal como están, solo puede usar valores 4 lugares después del decimal y una cosa más antes de la convolución aumente sus valores de imagen entre 0 y 1:

0.00253790859361804,0.00284879446220838,0.00314141610419987,0.00340305543986557,0.00362152753952273,0.00378611472031542,0.00388843599983945,0.00392315394879368,0.00388843599983945,0.00378611472031542,0.00362152753952273,0.00340305543986557,0.00314141610419987,0.00284879446220838,0.00253790859361804; 0.00284879446220838,0.00319776287779517,0.00352622975612324,0.00381991909245893,0.00406515334132644,0.00424990193722614,0.00436475725361032,0.00440372804277458,0.00436475725361032,0.00424990193722614,0.00406515334132644,0.00381991909245893,0.00352622975612324,0.00319776287779517,0.00284879446220838; 0.00314141610419987,0.00352622975612324,0.00388843599983945,0.00421229243210782,0.00448271658130972,0.00468644212981339,0.00481309512122034,0.00485606890058492,0.00481309512122034,0.00468644212981339,0.00448271658130972,0.00421229243210782,0.00388843599983945,0.00352622975612324,0.00314141610419987; 0.00340305543986557,0.00381991909245893,0.00421229243210782,0.00456312191696750,0.00485606890058492,0.00507676215263394,0.00521396370030743,0.00526051663974220,0.00521396370030743,0.00507676215263394,0.00485606890058492,0.00456312191696750,0.00421229243210782,0.00381991909245893,0.00340305543986557; 0.00362152753952273,0.00406515334132644,0.00448271658130972,0.00485606890058492,0.00516782273108746,0.00540268422664802,0.00554869395001131,0.00559823553262373,0.00554869395001131,0.00540268422664802,0.00516782273108746,0.00485606890058492,0.00448271658130972,0.00406515334132644,0.00362152753952273; 0.00378611472031542,0.00424990193722614,0.00468644212981339,0.00507676215263394,0.00540268422664802,0.00564821944786971,0.00580086485975791,0.00585265795345929,0.00580086485975791,0.00564821944786971,0.00540268422664802,0.00507676215263394,0.00468644212981339,0.00424990193722614,0.00378611472031542; 0.00388843599983945,0.00436475725361032,0.00481309512122034,0.00521396370030743,0.00554869395001131,0.00580086485975791,0.00595763557555571,0.00601082839853353,0.00595763557555571,0.00580086485975791,0.00554869395001131,0.00521396370030743,0.00481309512122034,0.00436475725361032,0.00388843599983945; 0.00392315394879368,0.00440372804277458,0.00485606890058492,0.00526051663974220,0.00559823553262373,0.00585265795345929,0.00601082839853353,0.00606449615428972,0.00601082839853353,0.00585265795345929,0.00559823553262373,0.00526051663974220,0.00485606890058492,0.00440372804277458,0.00392315394879368; 0.00388843599983945,0.00436475725361032,0.00481309512122034,0.00521396370030743,0.00554869395001131,0.00580086485975791,0.00595763557555571,0.00601082839853353,0.00595763557555571,0.00580086485975791,0.00554869395001131,0.00521396370030743,0.00481309512122034,0.00436475725361032,0.00388843599983945; 0.00378611472031542,0.00424990193722614,0.00468644212981339,0.00507676215263394,0.00540268422664802,0.00564821944786971,0.00580086485975791,0.00585265795345929,0.00580086485975791,0.00564821944786971,0.00540268422664802,0.00507676215263394,0.00468644212981339,0.00424990193722614,0.00378611472031542; 0.00362152753952273,0.00406515334132644,0.00448271658130972,0.00485606890058492,0.00516782273108746,0.00540268422664802,0.00554869395001131,0.00559823553262373,0.00554869395001131,0.00540268422664802,0.00516782273108746,0.00485606890058492,0.00448271658130972,0.00406515334132644,0.00362152753952273; 0.00340305543986557,0.00381991909245893,0.00421229243210782,0.00456312191696750,0.00485606890058492,0.00507676215263394,0.00521396370030743,0.00526051663974220,0.00521396370030743,0.00507676215263394,0.00485606890058492,0.00456312191696750,0.00421229243210782,0.00381991909245893,0.00340305543986557; 0.00314141610419987,0.00352622975612324,0.00388843599983945,0.00421229243210782,0.00448271658130972,0.00468644212981339,0.00481309512122034,0.00485606890058492,0.00481309512122034,0.00468644212981339,0.00448271658130972,0.00421229243210782,0.00388843599983945,0.00352622975612324,0.00314141610419987; 0.00284879446220838,0.00319776287779517,0.00352622975612324,0.00381991909245893,0.00406515334132644,0.00424990193722614,0.00436475725361032,0.00440372804277458,0.00436475725361032,0.00424990193722614,0.00406515334132644,0.00381991909245893,0.00352622975612324,0.00319776287779517,0.00284879446220838; 0.00253790859361804,0.00284879446220838,0.00314141610419987,0.00340305543986557,0.00362152753952273,0.00378611472031542,0.00388843599983945,0.00392315394879368,0.00388843599983945,0.00378611472031542,0.00362152753952273,0.00340305543986557,0.00314141610419987,0.00284879446220838,0.00253790859361804;

Máscara de Sobel:

1, 2, 1; 0, 0, 0; -1,-2, 1;

y

1, 0,-1; 2, 0,-2; 1, 0,-1;

Código de magnitud de gradiente Sobel (ImageFeatures.Gradient):

function [gx,gy,mag,phi] = Gradients(gray) gray = double(gray); horzmask = fspecial(''sobel''); % vertmask = horzmask''; gx = imfilter(gray,horzmask,''replicate''); gy = imfilter(gray,horzmask'',''replicate''); phi = (atan2((gy),(gx))); mag = mat2gray(sqrt(gx.^2+gy.^2)); end


Estoy siguiendo el procedimiento de Ankit Dixit para detectar rasguños y tener algunos problemas. En primer lugar, porque uso C ++ en lugar de MATLAB, me gustaría comprobar si existe algún malentendido sobre el algoritmo.

Por ahora, solo uso el Filtro Gaussian 5x5 porque está disponible. ¿Cuál es la razón por la que eligió el tamaño de ventana 15x15 en lugar de 5x5? En segundo lugar, mi imagen después de la máscara de Sobel no parece tan buena como la tuya. ¿Hay alguna especial / diferente en Sobel de Matlab?

Aquí hay imágenes: Gris: http://s15.postimg.org/q8s5y2sjf/Gray_Image.png Filtro gaussiano 5x5: http://s1.postimg.org/80r9x20tr/Gaussian_Filter_5x5.png Make Sobel: http://s21.postimg.org/vxwyju58n/Sobel_Image.png


He intentado el siguiente procedimiento para la detección. La salida parece moderada, pero aun así pensé en compartirla.

  • baja la muestra de la imagen en color.
  • aplique el difuminado mediano con diferentes tamaños de ventana, luego tome la diferencia absoluta: estoy haciendo esto para mejorar las marcas de rayado y al mismo tiempo lograr un aplanamiento de la iluminación. A continuación se muestran las imágenes de diferencia obtenidas de esta manera.

  • utilice la segmentación de fondo / primer plano basada en la mezcla gaussiana para segmentar las marcas de rayado en la imagen de diferencia. La idea aquí es, podemos extraer mxn windows de esta imagen y entrenar. Como las marcas de rayado no ocupan un área grande en la imagen de diferencia, podemos pensar que el fondo aprendido debe aproximarse a la región fuera de las marcas de rayado. Este método funcionó mejor para ambas imágenes de diferencia que aplicando un umbral a la imagen de diferencia. Este método no funcionó bien cuando alimenté la imagen muestreada directamente. Creo que esto se debe a la naturaleza no uniforme de los valores de color de los píxeles en las regiones. Así que usé la iluminación de la imagen de la diferencia aplanada. A continuación se muestran las imágenes segmentadas. Este procedimiento es lento ya que comprueba todas las ventanas mxn posibles en la imagen.

  • use la transformada de Hough probabilística para detectar líneas en la imagen segmentada. Usando la densidad de línea en regiones o usando filtros morfológicos para líneas, creo que es posible llegar a una estimación razonable de dónde están las marcas de rayado.

Aquí está el código

código de segmentación de fondo:

Mat threshold_mog(Mat& im, Size window) { BackgroundSubtractorMOG2 bgModel; Mat fgMask; Mat output = Mat::ones(im.rows, im.cols, CV_8U); for (int r = 0; r < im.rows - window.height; r++) { for (int c = 0; c < im.cols - window.width; c++) { bgModel.operator()(im(Rect(c, r, window.width, window.height)), fgMask); } } for (int r = 0; r < im.rows - window.height; r++) { for (int c = 0; c < im.cols - window.width; c++) { Mat region = im(Rect(c, r, window.width, window.height)); bgModel.operator()(region, fgMask, 0); fgMask.copyTo(output(Rect(c, r, window.width, window.height))); } } return output; }

principal:

Mat rgb = imread("scratch_2.png.jpg"); pyrDown(rgb, rgb); Mat med, med2, dif, bw; medianBlur(rgb, med, 3); medianBlur(rgb, med2, 21); absdiff(med2, med, dif); bw = threshold_mog(dif, Size(15, 15)); Mat dst = bw.clone(); vector<Vec4i> lines; HoughLinesP(dst, lines, 1, CV_PI/180, 8, 10, 20); for( size_t i = 0; i < lines.size(); i++ ) { Vec4i l = lines[i]; line(rgb, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 1, CV_AA); }