필터 지우기
필터 지우기

Matlab Motion Estimation Code

조회 수: 1 (최근 30일)
James
James 2011년 7월 14일
Hi
Can somebody please explain what the code I have pasted below does, which can be found from the Link - Algorithms
for i = 0:30
imgINumber = i;
imgPNumber = i+2;
if imgINumber < 10
imgIFile = sprintf('./%s/gray/%s00%d.ras',imageName, imageName, imgINumber);
elseif imgINumber < 100
imgIFile = sprintf('./%s/gray/%s0%d.ras',imageName, imageName, imgINumber);
end
if imgPNumber < 10
imgPFile = sprintf('./%s/gray/%s00%d.ras',imageName, imageName, imgPNumber);
elseif imgPNumber < 100
imgPFile = sprintf('./%s/gray/%s0%d.ras',imageName, imageName, imgPNumber);
end
I want to perform some of the motion estimation algorithms using my own mpeg video, but I need to know what this code does. It would be very much appreciated, as it will help me with my final year project.

답변 (2개)

bym
bym 2011년 7월 14일
it creates a string based upon the image name & number. It pads the number with zeros to get a string with a consistent number of characters

Walter Roberson
Walter Roberson 2011년 7월 14일
It is code for selecting file names from a directory relative to the current directory. The subdirectory involved is indicated by imageName and then the 'gray' subdirectory of that. The file names involved will start with that same name, followed by a 3 digit number, followed by '.ras'. For any one pass of the for loop over "i", two files are selected, one using i as the number, and the other using i+2
The code could be replaced with
for i = 0:30
imgIFile = sprintf('./%s/gray/%s%03d.ras', imageName, imageName, i);
imgPfile = sprintf('./%s/gray/%s%03d.ras', imageName, imageName, i+2);
  댓글 수: 2
James
James 2011년 7월 14일
That simplified code is helpful.
What does this part mean though - './%s/gray/%s%03d.ras'
Also, if I had all the images in one folder called gray, then what would the code look like?
Walter Roberson
Walter Roberson 2011년 7월 14일
'./%s/gray/%s%03d.ras' is an sprintf format string. It means that the output string is to start with a period, then a slash, then the next parameter (the 2nd to the call) should be interpreted as a string and placed in the buffer, followed by a slash and the literal word 'gray', followed by a slash, then the next parameter (the 3rd to the call) should be interpreted as a string and placed in the buffer, followed by a slash, then the next parameter (the 4th to the call) should be interpreted as a string and placed in the buffer, then the next parameter (the 5th to the call) should be converted to be a 3 digit integer with leading zeroes, and finally that a literal period and 'ras' should be added to the buffer.
If all the images are in a folder called gray that is a subdirectory of your current directory, then the code would look like:
for i = 0:30
imgIFile = sprintf('./gray/%s%03d.ras', imageName, i);
imgPfile = sprintf('./gray/%s%03d.ras', imageName, i+2);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by