Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
how to create mask

Subject: how to create mask

From: yusuf awal

Date: 10 Mar, 2010 07:43:10

Message: 1 of 7

Hi,
I have a region (say: in a matrix X=[250 52]),then I want to mask some area that I'm not interested in my analysis e.g. one area (60,2) to (60,7) and (90,2) to (90,7), how to do that in matlab? and what if I have more than one area to be masked?

thanks

ysf

Subject: how to create mask

From: Przemo :)

Date: 10 Mar, 2010 08:16:04

Message: 2 of 7

"yusuf awal" <awaludinium@yahoo.com> wrote in message <hn7iie$99r$1@fred.mathworks.com>...
> Hi,
> I have a region (say: in a matrix X=[250 52]),then I want to mask some area that I'm not interested in my analysis e.g. one area (60,2) to (60,7) and (90,2) to (90,7), how to do that in matlab? and what if I have more than one area to be masked?
>
> thanks
>
> ysf

I create binary mask if I am interested in some selected area. what means that some specific point won't be modified.
e.g.

% initialisation
mask = ones(size(X));
mask(60,2:7) = 0;

% processing step
Y = imfilter(X,ones(3,3)/9,'replicate');
Y(find(~mask)) = X(find(~mask));

Regards,
Przemo

Subject: how to create mask

From: Przemo :)

Date: 10 Mar, 2010 09:58:04

Message: 3 of 7

"yusuf awal" <awaludinium@yahoo.com> wrote in message <hn7iie$99r$1@fred.mathworks.com>...
> Hi,
> I have a region (say: in a matrix X=[250 52]),then I want to mask some area that I'm not interested in my analysis e.g. one area (60,2) to (60,7) and (90,2) to (90,7), how to do that in matlab? and what if I have more than one area to be masked?
>
> thanks
>
> ysf

Check roifilt2 function too !

Subject: how to create mask

From: ImageAnalyst

Date: 10 Mar, 2010 11:29:55

Message: 4 of 7

yusuf awal
Get a binary matrix of your matrix. Then multiply it by your other
matrix. Like this

maskedArray = originalMatrix .* logicalMatrix; % Note .* instead of *
If the originalMatirx is of integer type, then you'll have to cast
logicalMatrix to be the same integer type as originalMatrix.

Subject: how to create mask

From: yusuf awal

Date: 10 Mar, 2010 23:41:24

Message: 5 of 7

Hi Przemo,
Thanks for your suggestion. unfortunately I don't have imfilter and roifilt2 function, since I am using Matlab R2007a. any alternative for that?

thanks

ysf
<hn7iie$99r$1@fred.mathworks.com>...
> > Hi,
> > I have a region (say: in a matrix X=[250 52]),then I want to mask some area that I'm not interested in my analysis e.g. one area (60,2) to (60,7) and (90,2) to (90,7), how to do that in matlab? and what if I have more than one area to be masked?
> >
> > thanks
> >
> > ysf
>
> Check roifilt2 function too !

Subject: how to create mask

From: ImageAnalyst

Date: 11 Mar, 2010 02:52:31

Message: 6 of 7

On Mar 10, 6:41 pm, "yusuf awal" <awaludin...@yahoo.com> wrote:
> Hi Przemo,
> Thanks for your suggestion. unfortunately I don't have imfilter and   roifilt2 function, since I am using Matlab R2007a. any alternative for that?
>
> thanks
>
> ysf
------------------------------------------------------------------------------------------------------
Depends on what you want to do. Masking can be something as simple as
setting a region to zero if you're going to do something like
thresholding. Like this:

matrixX = uint8(254 * rand(250, 52)+1)
row1 = 60;
row2 = 90;
col1 = 2;
col2 = 7;
matrixX(row1:row2, col1:col2)
subplot(1,2, 1);
image(matrixX);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
title('Original 250x52 Array');
maskedMatrixX = matrixX; % Make it a copy, at first.
% Now do the masking - make it zero in the mask region.
maskedMatrixX(row1:row2, col1:col2) = 0;
subplot(1,2, 2);
image(maskedMatrixX);
% axis 'square';
title('Masked Array');

Subject: how to create mask

From: yusuf awal

Date: 13 Mar, 2010 05:14:07

Message: 7 of 7

Many thanks ImageAnalyst,
I understand how to create a mask now.
cheers

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <eb829c2d-0222-45a8-b515-bdd65f26e2c4@z35g2000yqd.googlegroups.com>...
> On Mar 10, 6:41 pm, "yusuf awal" <awaludin...@yahoo.com> wrote:
> > Hi Przemo,
> > Thanks for your suggestion. unfortunately I don't have imfilter and roifilt2 function, since I am using Matlab R2007a. any alternative for that?
> >
> > thanks
> >
> > ysf
> ------------------------------------------------------------------------------------------------------
> Depends on what you want to do. Masking can be something as simple as
> setting a region to zero if you're going to do something like
> thresholding. Like this:
>
> matrixX = uint8(254 * rand(250, 52)+1)
> row1 = 60;
> row2 = 90;
> col1 = 2;
> col2 = 7;
> matrixX(row1:row2, col1:col2)
> subplot(1,2, 1);
> image(matrixX);
> set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
> title('Original 250x52 Array');
> maskedMatrixX = matrixX; % Make it a copy, at first.
> % Now do the masking - make it zero in the mask region.
> maskedMatrixX(row1:row2, col1:col2) = 0;
> subplot(1,2, 2);
> image(maskedMatrixX);
> % axis 'square';
> title('Masked Array');

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us