Selecting ImageData Using Rows And Columns

Manipulate[
Module[{work=Table[0,{116},{150},{3}],channel},

If[r1>r2,r1=r2];
If[c1>c2,c1=c2];

channel=Which[
p1&&p2&&p3,1;;3,
p1&&Not[p2]&&Not[p3],1,
p1&&p2&&Not[p3],1;;2,
p1&&Not[p2]&&p3,{1,3},
Not[p1]&&p2&&p3,2;;3,
Not[p1]&&p2&&Not[p3],2,
Not[p1]&&p3&&Not[p2],3,
True,(p1=True;1)(*must have atleast one channel*)
];

work[[r1;;r2,c1;;c2,channel]]=data[[r1;;r2,c1;;c2,channel]];

Grid[{
{Row[{"ImageData[[ ",padIt2[r1,3],";;",padIt2[r2,3]," , ",padIt2[c1,3],";;",padIt2[c2,3]," , ",channel," ]]"}]},
{Grid[{
{ImageResize[Image[data],350],ImageResize[Image[work],350]}}]
}
},Alignment->Center,Frame->All,FrameStyle->LightGray,Spacings->{1,1}]
],

Style[Text[Grid[{
{
Grid[{
{"starting row",Control[{{r1,17,""},1,116,1,ImageSize->Tiny}],Spacer[2],Dynamic[padIt2[r1,3]]},
{"ending row",Control[{{r2,83,""},1,116,1,ImageSize->Tiny}],Spacer[2],Dynamic[padIt2[r2,3]]},
{"starting column",Control[{{c1,10,""},1,150,1,ImageSize->Tiny}],Spacer[2],Dynamic[padIt2[c1,3]]},
{"ending column",Control[{{c2,133,""},1,150,1,ImageSize->Tiny}],Spacer[2],Dynamic[padIt2[c2,3]]}
},Alignment->Left,Frame->True,FrameStyle->Directive[Thickness[.001],Gray]],

Grid[{
{"select color channel"},
{Grid[{
{"red",Checkbox[Dynamic[p1,{p1=#}&]]},
{"green",Checkbox[Dynamic[p2,{p2=#}&]]},
{"blue",Checkbox[Dynamic[p3,{p3=#}&]]}
},Alignment->Left,Spacings->{0.4,.7}]
}
},Alignment->Center,Frame->True,FrameStyle->Directive[Thickness[.001],Gray],Spacings->{0.5,.7}]

}
},Alignment->Center]
],12],

{{p1,True},None},
{{p2,True},None},
{{p3,True},None},
Alignment->Center,
ImageMargins->1,
FrameMargins->1,
Paneled->True,
AutorunSequencing-> Automatic,
SynchronousUpdating->True,
ContinuousAction->True,
SynchronousInitialization->False,
SynchronousUpdating->True,
Initialization:>
(
numeric=(Element[#,Reals]&);
padIt2[v_?numeric,f_Integer]:=AccountingForm[Chop[v] ,f,NumberSigns->{"",""},NumberPadding->{"0","0"},SignPadding->True];
data=ImageData[];
)

]

This demonstration shows how to select parts of an image using ImageData by specifying row and column locations. You can also select different color channels to view.

Contributed by: Nasser M. Abbasi