dice_score_multiple.m 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. % pick files from two folders
  2. allScores = [];
  3. for k = 1:124
  4. % Create an image filename, and read it in to a variable called imageData.
  5. %read real highlight image
  6. realHLfileName = strcat('./real_highlights/','B_', num2str(k+1),'_realB','.jpg');
  7. if exist(realHLfileName, 'file')
  8. realImage = imread(realHLfileName);
  9. else
  10. fprintf('File %s does not exist.\n', realHLfileName);
  11. end
  12. genHLfileName = strcat('./generated_highlights/','A_', num2str(k),'_A2B','.jpg');
  13. if exist(genHLfileName, 'file')
  14. genImage = imread(genHLfileName);
  15. else
  16. fprintf('File %s does not exist.\n', genHLfileName);
  17. end
  18. %imshowpair(I,BW,'montage');
  19. realIgray = rgb2gray(realImage);
  20. genIgray = rgb2gray(genImage);
  21. realBW = imbinarize(realIgray);
  22. genBW = imbinarize(genIgray);
  23. % figure(1);
  24. %
  25. % imshowpair(realImage,realIgray,'montage');
  26. % figure(2);
  27. % %,genImage,genIgray,genBW,
  28. % imshowpair(realBW,genBW,'montage');
  29. %
  30. % figure(3);
  31. % imshowpair(I,BW,'montage');
  32. %
  33. andImage = realBW & genBW;
  34. orImage = realBW | genBW;
  35. diceCoeff = sum(andImage) / sum(orImage);
  36. disp(diceCoeff);
  37. allScores = [allScores, diceCoeff];
  38. end
  39. disp(allScores);
  40. meanScore = mean(allScores);
  41. disp("-------");
  42. disp(meanScore);