Extracting window with morphological method?

as16.m (2.1 KB) sh3.m (412 Bytes) sh5.m (331 Bytes)
Hi I am trying to extract windows of this image . and these are Matlab algorithms .which line I should change to come to conclusion.Thank you so much