loop and graph problem (time vs area)
조회 수: 2 (최근 30일)
이전 댓글 표시
I have series of images something look like this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/145245/image.jpeg)
each image was taken with increment of time (interval of 5 seconds) and I need to compute the area of each image then make a graph (x-axis: time , y-axis: area)
I think I should use loop function (repeating same method), and length (to calculate the number of file) Then at the end, make a graph. But
@@@@@@@@@@@@Here is my code which opens just one image. (works well)@@@@@@@@@@@@@@
a=imread ('rose1.jpg'); % read image
b= rgb2gray (a); %chagne to gray image
c= im2bw(b) % change to black and white image
regions1and2 = imclearborder(~c); clear the border region
area = bwarea(regions1and2); % calculate the area of region 1 and 2
@@@@@@@@@here is other code that does not work well@@@@@@@@@
clc;
clear;
path= 'F:\Thesis data\'
file= dir([path 'jpg']);
n_file=length(file); count number of files
x = 1:1:10
for i = 1:n_file
temp = imread([path file(i).name])'
temp2 = rgb2gray (temp)
temp3 = im2bw(temp2)
temp4 = imclearborder(~temp3);
area = bwarea(temp4);
end
plot(x,i);
xlabel('Time(second)','FontSize',10)
ylabel('area','FontSize',10)
댓글 수: 0
채택된 답변
Iain
2014년 9월 2일
problem 1: Looks like your dir call should be "dir([path '*.jpg'])
problem 2: Looks like area = bwarea(temp4); should be area(i) = bwarea(temp4);
problem 3: plot(x,i); should be plot(1:n_files,area);
댓글 수: 0
추가 답변 (1개)
Joseph Cheng
2014년 9월 2일
in your for loop you'll need to save the value of your calculated bwarea. if you do not then you're just over writing the value over and over in each iteration. you'll need to use something like
area(i) = bwarea(temp4);
then you should be able to plot(x,area).
댓글 수: 1
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!