To find islands of 1 and 0 in matrix
APL (Dyalog Unicode), 29 28 bytesSBCS

-1 thanks to @Adám



{≢∪∨.∧⍨⍣≡2&gt;+/↑|∘.-⍨⍸⍵}¨⊂,~∘⊂


Try it online!

⊂,~∘⊂ the matrix and its negation

{ }¨ for each of them do

⍸⍵ list of pairs of coords of 1s

+/↑|∘.-⍨ matrix of manhattan distances

2&gt; neighbour matrix

∨.∧⍨⍣≡ transitive closure

≢∪ number of unique rows