Advertisement
makispaiktis

Image Processing Onramp - Course 8 - CLASSIFY IMAGE

Aug 4th, 2023
930
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.75 KB | None | 0 0
  1. % 1. Select the 1st image of the datastore
  2.  
  3. ds = imageDatastore("testimages");
  4. I = readimage(ds, 1);
  5. imshow(I);
  6. isReceipt = classifyImage(I)
  7.  
  8.  
  9.  
  10. % 2. Classify Image
  11.  
  12. function isReceipt = classifyImage(I)
  13.    
  14.     gs = im2gray(I);
  15.     gs = imadjust(gs);
  16.    
  17.     mask = fspecial("average",3);
  18.     gsSmooth = imfilter(gs,mask,"replicate");
  19.    
  20.     SE = strel("disk",8);  
  21.     Ibg = imclose(gsSmooth, SE);
  22.     Ibgsub =  Ibg - gsSmooth;
  23.  
  24.     Ibw = ~imbinarize(Ibgsub);
  25.    
  26.     SE = strel("rectangle",[3 25]);
  27.     stripes = imopen(Ibw, SE);
  28.     signal = sum(stripes,2);  
  29.  
  30.     % Classification
  31.     minIndices = islocalmin(signal,"MinProminence",70,"ProminenceWindow",25);
  32.     Nmin = nnz(minIndices);
  33.     isReceipt = Nmin >= 9;
  34.    
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement