Output for visdiff?
조회 수: 5 (최근 30일)
이전 댓글 표시
I have two directories with subdirectories to compare. I have a main folder full of images in several different subfolders that is considered "correct" (I am doing this for a professor) and I have another folder that has all the same subdirectories as the main folder but the images are not in the same subdirectories as the main folder. I used visdiff to compare the two, put I would also like a text output saying which files match and which don't. This is what I have so far:
mainPath = '/Documents/Lesson_Italy_2015/';
studentsFolder = '/Documents/Lesson_Italy_2015 copy/';
choosenFolder = uigetdir(studentsFolder);
if choosenFolder == 0
return;
end
visdiff(mainPath,choosenFolder)
Thank you in advance for the help.
댓글 수: 2
Walter Roberson
2015년 9월 16일
images are compared as binary files, so they would have to be exactly the same in every respect to be considered equal. But two image files with exactly the same image content but saved at different times would usually have different time-stamps written into them, so the binary files would not be identical. If you are looking for the image content to be the same you need to load the images and compare them. You also have to decide whether you want to support different image file formats as being equal, such as if one person saved as TIF and the other as PNG. If that is to be allowed, you need to take into account that JPEG files are lossy and would not usually have exactly the same image content as the lossless TIF or PNG formats even if the data being written out was the same.
So first you have to define exactly what you need to compare.
채택된 답변
per isakson
2015년 9월 16일
편집: per isakson
2015년 9월 18일
"What needs to be compared is the file name"
Try this
main = dir( mainPath );
user = dir( choosenFolder );
main( [main.isdir] ) = [];
user( [user.isdir] ) = [];
files_not_in_choosenFolder = setdiff( {main.name}, {user.name} );
files_not_in_mainPath = setdiff( {user.name}, {main.name} );
if isempty(files_not_in_choosenFolder) && isempty(files_not_in_mainPath)
disp( 'same files in the two folders' )
end
If on Windows you might want to use lower case.
files_not_in_choosenFolder = setdiff( lower({main.name}), lower({user.name}) );
files_not_in_mainPath = setdiff( lower({user.name}), lower({main.name}) );
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 File Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!