Advertisement
Rementai

LAB05

Nov 9th, 2022
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.55 KB | None | 0 0
  1. clc
  2. clear all
  3. close all
  4.  
  5. rice = imread("rice.png");
  6. katalog = imread("katalog.bmp");
  7.  
  8. [X Y] = size(rice);
  9. obrazBW = rice;
  10.  
  11. for i=1:256
  12.     for y=1:256
  13.         srednia(i,y) = meanLT(i,y,7,rice,X,Y);
  14.         if rice(i,y) >= srednia(i,y)
  15.             obrazBW(i,y) = 255;
  16.         else
  17.             obrazBW(i,y) = 0;
  18.         end
  19.     end
  20. end
  21.  
  22. figure(1)
  23. subplot(1,2,1)
  24. imshow(rice)
  25. subplot(1,2,2)
  26. imshow(obrazBW)
  27.  
  28. [X1 Y1] = size(katalog);
  29.  
  30. obrazBW2 = katalog;
  31.  
  32. for i=1:256
  33.     for y=1:256
  34.         srednia(i,y) = meanLT(i,y,7,katalog,X1,Y1);
  35.         if katalog(i,y) >= srednia(i,y)
  36.             obrazBW2(i,y) = 255;
  37.         else
  38.             obrazBW2(i,y) = 0;
  39.         end
  40.     end
  41. end
  42.  
  43. testU1 = uint8(obrazBW2);
  44.  
  45. figure(2)
  46. subplot(1,2,1)
  47. imshow(katalog)
  48. subplot(1,2,2)
  49. imshow(obrazBW2)
  50.  
  51. k = 0.15;
  52. R = 128;
  53.  
  54. obrazBW3 = rice;
  55.  
  56. for i=1:1:256
  57.     for y=1:1:256
  58.         srednia = meanLT(i,y,7,rice,X,Y);
  59.         m = stddevLT(i,y,7,rice,srednia,X,Y);
  60.         T(i,y) = srednia * ( 1 - k *((m/R) -1 ));
  61.         if rice(i,y) >= T(i,y)
  62.             obrazBW3(i,y) = 255;
  63.         else
  64.             obrazBW3(i,y) = 0;
  65.         end
  66.     end
  67. end
  68.  
  69. figure(3)
  70. imshow(obrazBW3)
  71.  
  72. obrazBW4 = katalog;
  73.  
  74. for i=1:256
  75.     for y=1:256
  76.         srednia = meanLT(i,y,7,katalog,X,Y);
  77.         m = stddevLT(i,y,7,katalog,srednia,X,Y);
  78.         T(i,y) = srednia * ( 1 + k *((m/R) -1 ));
  79.         if katalog(i,y) >= T(i,y)
  80.             obrazBW4(i,y) = 255;
  81.         else
  82.             obrazBW4(i,y) = 0;
  83.         end
  84.     end
  85. end
  86.  
  87. figure(4)
  88. imshow(obrazBW4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement