Advertisement
makispaiktis

Image Processing Onramp - Course 3 - Adaptive Thresholding

Aug 1st, 2023
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.80 KB | None | 0 0
  1. % 1. Load, grayscale, adjust
  2. img = imread("IMG_001.jpg");
  3. gs = im2gray(img);
  4. gsAdj = imadjust(gs);
  5. imshow(gsAdj)
  6.  
  7. % 2. Automatic image segmentation ("Global") - Same threshold for all the image
  8. BW = imbinarize(gsAdj);
  9. imshow(BW)
  10.  
  11. % 3. Adaptive image segmentation ("Adaptive") - Different threshold by regions
  12. BWadapt = imbinarize(gsAdj, "adaptive");
  13. imshowpair(gsAdj, BWadapt, "montage");
  14.  
  15. % 4. Adaptive image segmentation ("Adaptive") with foreground polarity
  16. BWadapt = imbinarize(gsAdj, "adaptive", "ForegroundPolarity","dark");
  17. imshowpair(gsAdj, BWadapt, "montage");
  18.  
  19. % 5. Same process for a different image
  20. img2 = imread("IMG_005.jpg");
  21. gs2 = im2gray(img2);
  22. gsAdj2 = imadjust(gs2);
  23. BWadapt2 = imbinarize(gsAdj2, "adaptive", "ForegroundPolarity","dark");
  24. imshowpair(BWadapt, BWadapt2, "montage")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement