From: Loren_Shure on

"Mirko " <arnoldma(a)tcd.ie> wrote in message
news:hvq0sk$gkr$1(a)fred.mathworks.com...
> Hi, I made some search attempts for this but was not successful.
>
> I work a lot with colour images (M x N x 3) and often would like to
> access, say, the red channel (M x N) of an image and use 2D logical
> indexing within that channel.
>
> The only ways I know to do this is either to create a new variable just
> for the red channel and then index into that or to extend the dimensions
> of the indexing matrix to M x N x 3.
>
> Is there a way to do this indexing directly. Intuitively I would write
> with the image IMG and the logical indexing matrix L:
>
> IMG(:,:,1)(L)
>
> which doesn't work but hopefully explains what I'd like to do.
>
> Many thanks!

How about

IMG(L(1),L(2),1)

--Loren

From: Mirko on
"Loren_Shure" <loren.shure(a)mathworks.com> wrote in message <hvqfps$lfv$1(a)fred.mathworks.com>...
>
> "Mirko " <arnoldma(a)tcd.ie> wrote in message
> news:hvq0sk$gkr$1(a)fred.mathworks.com...
> > Hi, I made some search attempts for this but was not successful.
> >
> > I work a lot with colour images (M x N x 3) and often would like to
> > access, say, the red channel (M x N) of an image and use 2D logical
> > indexing within that channel.
> >
> > The only ways I know to do this is either to create a new variable just
> > for the red channel and then index into that or to extend the dimensions
> > of the indexing matrix to M x N x 3.
> >
> > Is there a way to do this indexing directly. Intuitively I would write
> > with the image IMG and the logical indexing matrix L:
> >
> > IMG(:,:,1)(L)
> >
> > which doesn't work but hopefully explains what I'd like to do.
> >
> > Many thanks!
>
> How about
>
> IMG(L(1),L(2),1)
>
> --Loren

This will just use the first and second element of L. So if I am lucky and none of them is zero, I'll get IMG(1,1,1) :-)

Thanks very much anyway!