find 0 crossing points trough all the image rows
Hello all,
I have a vertical laser stripe image and my goal is to find the 0 crossing point of every row of the image in order to plot them as points afterwards.
This is my code, I have done the process for one row of the image. Now I have problems to do this same process for all the rows of the image. I’m trying to do that with a for loop but no way.
Resuming, is to to apply this same code for all the image rows. Thanks in advance!
clc; clear; close all;
%% calibracion de laser real con blur
%cargar la imagen que se va a medir
img=imread(fullfile(‘LaserTestPatternBlurred.bmp’));
img=imrotate(img,90);
% imshow(img)
% title(‘Imagen original’)
%% procesado de la imagen
img_o=rgb2gray(img);
%mask = (I(:, :, 1) > 100) & (I(:, :, 2) > 100);
mask=(img_o(:,:) > 50);
img = bsxfun(@times, img_o, cast(mask, ‘like’, img_o));
% figure()
% imshow(img)
% title(‘Binarizada’)
%% seleccionar una linea de la imagen y buscar su 0 crossing
[rows, columns, numberOfColorChannels] = size(img);
%seleccionamos la linea 900 y se le aplica un filtro para suavizar
linea=img(900,:);
sm=sgolayfilt(double(linea),2,25);
% figure()
% plot(img_o(900,:),’b’)
% hold on
% plot(linea,’r’)
% plot(sm,’g’)
% grid on
% ylim([0 255])
% title(‘Linea’)
% legend(‘imagen’,’linea’,’filtrado’)
% hold off
%buscamos los picos maximos de la gradiente
Lder=gradient(sm);
[picosp,locsp]=findpeaks(Lder);
[picosn,locsn]=findpeaks(-Lder);
% figure()
% plot(Lder)
% hold on
% scatter(locsn(1,2),-picosn(1,2),’g’)
% scatter(locsp(1,1),picosp(1,1),’g’)
% plot([locsn(1,2) locsp(1,1)],[-picosn(1,2) picosp(1,1)])
% axis([450 550 -15 15])
% grid on
%obtener la ecuacion de la recta entre los maximos y el paso por 0
recta = polyfit([locsp, locsn], [picosp, -picosn], 1);
a = recta (1);
b = recta (2);
subpixel= -b/(a);
scatter(subpixel,0,’r’)
hold offHello all,
I have a vertical laser stripe image and my goal is to find the 0 crossing point of every row of the image in order to plot them as points afterwards.
This is my code, I have done the process for one row of the image. Now I have problems to do this same process for all the rows of the image. I’m trying to do that with a for loop but no way.
Resuming, is to to apply this same code for all the image rows. Thanks in advance!
clc; clear; close all;
%% calibracion de laser real con blur
%cargar la imagen que se va a medir
img=imread(fullfile(‘LaserTestPatternBlurred.bmp’));
img=imrotate(img,90);
% imshow(img)
% title(‘Imagen original’)
%% procesado de la imagen
img_o=rgb2gray(img);
%mask = (I(:, :, 1) > 100) & (I(:, :, 2) > 100);
mask=(img_o(:,:) > 50);
img = bsxfun(@times, img_o, cast(mask, ‘like’, img_o));
% figure()
% imshow(img)
% title(‘Binarizada’)
%% seleccionar una linea de la imagen y buscar su 0 crossing
[rows, columns, numberOfColorChannels] = size(img);
%seleccionamos la linea 900 y se le aplica un filtro para suavizar
linea=img(900,:);
sm=sgolayfilt(double(linea),2,25);
% figure()
% plot(img_o(900,:),’b’)
% hold on
% plot(linea,’r’)
% plot(sm,’g’)
% grid on
% ylim([0 255])
% title(‘Linea’)
% legend(‘imagen’,’linea’,’filtrado’)
% hold off
%buscamos los picos maximos de la gradiente
Lder=gradient(sm);
[picosp,locsp]=findpeaks(Lder);
[picosn,locsn]=findpeaks(-Lder);
% figure()
% plot(Lder)
% hold on
% scatter(locsn(1,2),-picosn(1,2),’g’)
% scatter(locsp(1,1),picosp(1,1),’g’)
% plot([locsn(1,2) locsp(1,1)],[-picosn(1,2) picosp(1,1)])
% axis([450 550 -15 15])
% grid on
%obtener la ecuacion de la recta entre los maximos y el paso por 0
recta = polyfit([locsp, locsn], [picosp, -picosn], 1);
a = recta (1);
b = recta (2);
subpixel= -b/(a);
scatter(subpixel,0,’r’)
hold off Hello all,
I have a vertical laser stripe image and my goal is to find the 0 crossing point of every row of the image in order to plot them as points afterwards.
This is my code, I have done the process for one row of the image. Now I have problems to do this same process for all the rows of the image. I’m trying to do that with a for loop but no way.
Resuming, is to to apply this same code for all the image rows. Thanks in advance!
clc; clear; close all;
%% calibracion de laser real con blur
%cargar la imagen que se va a medir
img=imread(fullfile(‘LaserTestPatternBlurred.bmp’));
img=imrotate(img,90);
% imshow(img)
% title(‘Imagen original’)
%% procesado de la imagen
img_o=rgb2gray(img);
%mask = (I(:, :, 1) > 100) & (I(:, :, 2) > 100);
mask=(img_o(:,:) > 50);
img = bsxfun(@times, img_o, cast(mask, ‘like’, img_o));
% figure()
% imshow(img)
% title(‘Binarizada’)
%% seleccionar una linea de la imagen y buscar su 0 crossing
[rows, columns, numberOfColorChannels] = size(img);
%seleccionamos la linea 900 y se le aplica un filtro para suavizar
linea=img(900,:);
sm=sgolayfilt(double(linea),2,25);
% figure()
% plot(img_o(900,:),’b’)
% hold on
% plot(linea,’r’)
% plot(sm,’g’)
% grid on
% ylim([0 255])
% title(‘Linea’)
% legend(‘imagen’,’linea’,’filtrado’)
% hold off
%buscamos los picos maximos de la gradiente
Lder=gradient(sm);
[picosp,locsp]=findpeaks(Lder);
[picosn,locsn]=findpeaks(-Lder);
% figure()
% plot(Lder)
% hold on
% scatter(locsn(1,2),-picosn(1,2),’g’)
% scatter(locsp(1,1),picosp(1,1),’g’)
% plot([locsn(1,2) locsp(1,1)],[-picosn(1,2) picosp(1,1)])
% axis([450 550 -15 15])
% grid on
%obtener la ecuacion de la recta entre los maximos y el paso por 0
recta = polyfit([locsp, locsn], [picosp, -picosn], 1);
a = recta (1);
b = recta (2);
subpixel= -b/(a);
scatter(subpixel,0,’r’)
hold off laser stripe, calibration, 0 crossing MATLAB Answers — New Questions