How the brain generates visual percepts is a central problem in neuroscience. We propose a detailed neural model of how lateral geniculate nuclei and the interblob cortical stream through V1 and V2 generate context-sensitive perceptual groupings from visual inputs. The model suggests a functional role for cortical layers, columns, maps and networks, and proposes homologous circuits for V1 and V2 with larger-scale processing in V2. An integrated treatment of interlaminar, horizontal, orientational and endstopping cortical interactions and a role for corticogeniculate feedback in grouping are proposed. Modeled circuits simulate parametric psychophysical data about boundary grouping and illusory contour formation.