Hello everyone, how to record and save the coordinates of each image centroid point in a matrix in 'for loop'. Thank you very much. The code is as follows:

조회 수: 1 (최근 30일)
Hello everyone, how to record and save the coordinates of each image centroid point in a matrix.There are some problems in curve fitting. Thank you for your answers Thank you very much. The code is as follows:
CODE:
[filename1, pathname1] = uigetfile({'Dune.MP4'},'File Selector');
videoObject=VideoReader([pathname1,filename1]);
% % videoObject= VideoReader('Dune.MP4');
%Framerate=videoObject.FrameRate;
fig1=zeros(1000,1000);
numberOfFrames = videoObject.NumFrames;
centroids=[];
for i=1:numberOfFrames %for all frames in the range defined numberOfFrames
frame=read(videoObject,i);
%frame = rgb2gray(read(videoObject,i)); %turn all stated frames in the video from color to greyscale
J = rgb2gray(frame);
imwrite(J,'myGray.png')
I = imread('myGray.png ');
%imshow(I)
[~,threshold] = edge(I,'sobel');
fudgeFactor = 0.4;
BWs = edge(I,'sobel',threshold * fudgeFactor);
%imshow(BWs)
%title('Binary Gradient Mask')
se90 = strel('line',3,90);
se0 = strel('line',3,0);
BWsdil = imdilate(BWs,[se90 se0]);
%imshow(BWsdil)
%title('Dilated Gradient Mask')
BWdfill = imfill(BWsdil,'holes');
%imshow(BWdfill)
%title('Binary Image with Filled Holes')
BWnobord = imclearborder(BWdfill,4);
%imshow(BWnobord)
%title('Cleared Border Image')
seD = strel('diamond',1);
BWfinal = imerode(BWnobord,seD);
BWfinal = imerode(BWfinal,seD);
%imshow(BWfinal)
imwrite(BWfinal,'L.png')
%title('Segmented Image');
BW = imread('L.png');
BW2 = bwareaopen(BW, 700);
% figure;
% subplot(1,2,1)
% imshow(BW2);
axis on
% % subplot(1,2,2)
I2=flipud(BW2);
% imshow(I2);
axis on
set(gca,'YDir','normal')
%imshow(BW2)%imshowpair(BW,BW2,'montage')
imwrite(I2,'m.jpg')
BW3 = bwperim(I2,8);
BW4 = bwareaopen(BW3, 700);
%imshow(BW4)
imwrite(BW4,'k.png')
BW = imread('k.png');
s = regionprops(BW,'centroid');
centroids= cat(1,s.Centroid);
plot(THETA,RHO,'-')
hold on
curvefit = fit(centroids(1),centroids(2),'poly3','normalize','on');
plot(curvefit,centroids(1),centroids(2))
hold on
formula(curvefit)
end

채택된 답변

KSSV
KSSV 2021년 6월 10일
편집: KSSV 2021년 6월 10일
centroids = cell(numberOfFrames ,1) ;
for i = 1:numberOfFrames
centroids{i} = s.Centroid;
end

추가 답변 (0개)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by