Output for visdiff?

6 次查看(过去 30 天)
lreplo
lreplo 2015-9-16
评论: lreplo 2015-9-18
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
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.
lreplo
lreplo 2015-9-16
What needs to be compared is the file name, not what the actual image looks like. So for example: STUDENT = '/Documents/Lesson_Italy_2015 copy/Acantharian/image83.png'
MAIN = '/Documents/Lesson_Italy_2015/Acantharian/image83.png'
Since those match, it would be correct and output that the files match both directories. There are 63 subdirectories with over 355 images scattered in the 63 subdirectories.

请先登录,再进行评论。

采纳的回答

per isakson
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 CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by