Created
October 30, 2017 23:04
-
-
Save lordloh/fbede42a6ea23a0c1f121b1308870b07 to your computer and use it in GitHub Desktop.
A MATLAB function to generate a mask for playing cards
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mask=card_mask(img) | |
BW_a=imbinarize(img,'adaptive'); | |
BW_g=imbinarize(img,'global'); | |
cc_a=bwconncomp(BW_a,4); | |
cc_g=bwconncomp(BW_g,4); | |
obj_sizes_a=cellfun('length',cc_a.PixelIdxList); | |
obj_sizes_g=cellfun('length',cc_g.PixelIdxList); | |
[px_count_a,idx_a]=max(obj_sizes_a); | |
[px_count_g,idx_g]=max(obj_sizes_g); | |
mask=false(size(img)); | |
mask_idx=intersect(cc_a.PixelIdxList{idx_a},cc_g.PixelIdxList{idx_g}); | |
mask(mask_idx)=true; | |
mask=imfill(mask,'holes'); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment