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!