Advertisement
makispaiktis

Image Processing Onramp - Course 5 - Spatial Filtering

Aug 2nd, 2023
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.71 KB | None | 0 0
  1. % 1. Read, grayscale, adjust, binarize
  2. I = imread("IMG_007.jpg");
  3. gs = im2gray(I);
  4. gs = imadjust(gs);
  5. BW = imbinarize(gs,"adaptive","ForegroundPolarity","dark");
  6. imshowpair(gs,BW,"montage")
  7.  
  8. % 2. Create and apply a 3x3 filter
  9. H = fspecial("average", 3);
  10. gssmooth = imfilter(gs, H);
  11. BWsmooth = imbinarize(gssmooth,"adaptive","ForegroundPolarity","dark");
  12. imshow(BWsmooth);
  13.  
  14. % 3. The above image contains an artificial border
  15. gssmooth = imfilter(gs, H, "replicate");
  16. BWsmooth = imbinarize(gssmooth,"adaptive","ForegroundPolarity","dark");
  17. imshow(BWsmooth);
  18.  
  19. % 4. Compare the row sums
  20. S2 = sum(BW, 2);
  21. S3 = sum(BWsmooth, 2);
  22. figure(1);
  23. plot(S2, 'red')
  24. hold on
  25. plot(S3, 'green')
  26. legend("No smooth", "Smooth")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement