Save 360 arrays in a cell
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
mikel lasa
el 15 de Abr. de 2021
Respondida: mikel lasa
el 15 de Abr. de 2021
Hello,
My programs loads 360 images (laser stripe) and from each image gets the 0 crossing of all rows. My issue is that after processing all images, im not able to save the 0 crossing arrays into a cell so I can post process them. Here my code:
clc; clear all; close all;
%% CARGAR LAS IMAGENES (load images)
for k = 1:360
jpgFilename = sprintf('%d.jpg', k);
fullFileName = fullfile('C:\MASTER\S2\percepcion\laser360\imagenes', jpgFilename);
if exist(fullFileName, 'file')
imageData = imread(fullFileName );
imageData=imrotate(imageData,90);
% se binariza la imagen (binarization)
img_o=rgb2gray(imageData);
mask=(img_o(:,:) > 50);
imageData = bsxfun(@times, img_o, cast(mask, 'like', img_o));
% figure()
% imshow(imageData)
% title('Binarizada')
%
[rows, columns, numberOfColorChannels] = size(imageData);
img_peaks = NaN(rows, 1);
img_puntos = zeros(rows, columns);
Xp = [];
Yp = [];
Xn=[];
Yn=[];
m=[];
n=[];
zerocross=[];
coefficients=[];
lineaslaser=cell(k,1);
%se busca la linea del 0 crossing
for icross=1:rows
img_puntos(icross,:)=imageData(icross,:);
%filtrado
filtrado=sgolayfilt(double(img_puntos(icross,:)),3,33 );
for ks=1:length(filtrado)
if filtrado(ks)<0
filtrado(ks)=0;
end
end
%derivada (gradient)
derivada=gradient(filtrado);
%maximo y minimo
[Yp(icross),Xp(icross)]=max(derivada);
[Yn(icross),Xn(icross)]=min(derivada);
%coeficientes de la recta (line coefs)
m(icross)= (Yp(icross)-Yn(icross))/(Xp(icross)-Xn(icross));
n(icross)= (Yp(icross)-m(icross)*Xp(icross));
% 0 crossing
zerocross(icross)= -n(icross)/m(icross);
img_peaks(icross) = zerocross(icross);
end
axis=1:1920;
img_peaks((1:10),1)=NaN;
img_peaks((1500:1920),1)=NaN;
% save 360 lines in a cell
lineaslaser{k}=img_peaks(k);
% figure()
% plot(axis,img_peaks)
% title('plot perfil de la pieza (0 crossing)')
else
warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
end
3 comentarios
DGM
el 15 de Abr. de 2021
Okay. If you move the preallocation outside the main loop and set that line to
lineaslaser{k}=img_peaks;
does it help?
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Image Processing Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!