Save 360 arrays in a cell
조회 수: 2 (최근 30일)
이전 댓글 표시
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
DGM
2021년 4월 15일
Okay. If you move the preallocation outside the main loop and set that line to
lineaslaser{k}=img_peaks;
does it help?
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!