Output for visdiff?

2 views (last 30 days)
lreplo
lreplo on 16 Sep 2015
Commented: lreplo on 18 Sep 2015
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 Comments
Walter Roberson
Walter Roberson on 16 Sep 2015
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 on 16 Sep 2015
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.

Sign in to comment.

Accepted Answer

per isakson
per isakson on 16 Sep 2015
Edited: per isakson on 18 Sep 2015
"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}) );
  1 Comment
lreplo
lreplo on 18 Sep 2015
This worked wonderfully! Thank you!!

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!