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:
define a neighbourhood

Subject: define a neighbourhood

From: PinkLab

Date: 21 Apr, 2010 10:12:29

Message: 1 of 4

can anyone tell me how to define a suitable neighbourhood within the loaded image array please?

Subject: define a neighbourhood

From: Sean

Date: 21 Apr, 2010 11:12:05

Message: 2 of 4

"PinkLab " <pinklab@pinklab.com> wrote in message <hqmj2d$pnl$1@fred.mathworks.com>...
> can anyone tell me how to define a suitable neighbourhood within the loaded image array please?

Define Suitable.


I = magic(400);
side = 15;
nhood_ctr = [200, 200];
nhood = I((nhood_ctr(1)-floor(side/2)):(nhood_ctr(1)+floor(side/2)),(nhood_ctr(2)-floor(side/2)):(nhood_ctr(2)+floor(side/2)))
%If you want an even number side you'll have pick whether you want more points below or above the center point.

Subject: define a neighbourhood

From: PinkLab

Date: 21 Apr, 2010 11:39:05

Message: 3 of 4

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hqmmi5$pvg$1@fred.mathworks.com>...
> "PinkLab " <pinklab@pinklab.com> wrote in message <hqmj2d$pnl$1@fred.mathworks.com>...
> > can anyone tell me how to define a suitable neighbourhood within the loaded image array please?
>
> Define Suitable.
>
>
> I = magic(400);
> side = 15;
> nhood_ctr = [200, 200];
> nhood = I((nhood_ctr(1)-floor(side/2)):(nhood_ctr(1)+floor(side/2)),(nhood_ctr(2)-floor(side/2)):(nhood_ctr(2)+floor(side/2)))
> %If you want an even number side you'll have pick whether you want more points below or above the center point.

thanks this is cool, i have done it on my image and it looks like it shows me the neighborhood of the image

I = imread('image.jpg');
side = 15; % not sure what this for??
nhood_ctr = [200, 200]; % not sure what this for and 200, 200 for??

nhood = I((nhood_ctr(1)-floor(side/2)):(nhood_ctr(1)+floor(side/2)),(nhood_ctr(2)-floor(side/2)):(nhood_ctr(2)+floor(side/2)))

% what is happening in this last line?

WORKSPACE OUTPUT

nhood =

  234 236 251 234 239 227 240 241 245 225 251 234 228 250 232
  248 245 236 238 246 247 246 234 242 238 239 246 235 245 238
  245 223 0 251 233 230 246 244 231 251 230 240 249 238 232
  241 245 251 235 233 238 237 237 247 250 240 226 240 244 245
  230 239 226 251 251 238 246 241 242 223 251 251 228 238 231
  246 251 231 232 236 223 251 237 230 251 232 0 244 248 240
  235 237 246 242 251 244 242 230 242 235 246 237 237 246 239
  242 234 240 238 236 239 234 246 237 241 229 251 235 241 238
  240 240 250 234 230 251 224 246 240 240 240 240 240 240 240
  232 237 230 245 0 221 251 225 240 240 240 240 240 240 240
  243 243 251 226 251 247 228 244 240 240 240 240 240 240 240
  242 223 227 235 238 247 231 247 240 240 240 240 240 240 240
  222 242 251 228 248 237 235 235 240 240 240 240 240 240 240
  251 230 229 245 230 238 243 237 240 240 240 240 240 240 240
  224 234 251 248 235 238 251 231 240 240 240 240 240 240 240

i believe this is my complete image......now how do i move around this neighborhoods?

and how do i apply my filters to remove noise from this?

thanks alot

Subject: define a neighbourhood

From: Sean

Date: 21 Apr, 2010 12:06:23

Message: 4 of 4

"PinkLab " <pinklab@pinklab.com> wrote in message <hqmo4p$lnf$1@fred.mathworks.com>...
> "Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <hqmmi5$pvg$1@fred.mathworks.com>...
> > "PinkLab " <pinklab@pinklab.com> wrote in message <hqmj2d$pnl$1@fred.mathworks.com>...
> > > can anyone tell me how to define a suitable neighbourhood within the loaded image array please?
> >
> > Define Suitable.
> >
> >
> > I = magic(400);
> > side = 15;
> > nhood_ctr = [200, 200];
> > nhood = I((nhood_ctr(1)-floor(side/2)):(nhood_ctr(1)+floor(side/2)),(nhood_ctr(2)-floor(side/2)):(nhood_ctr(2)+floor(side/2)))
> > %If you want an even number side you'll have pick whether you want more points below or above the center point.
>
> thanks this is cool, i have done it on my image and it looks like it shows me the neighborhood of the image
>
> I = imread('image.jpg');
> side = 15; % not sure what this for??
> nhood_ctr = [200, 200]; % not sure what this for and 200, 200 for??
>
> nhood = I((nhood_ctr(1)-floor(side/2)):(nhood_ctr(1)+floor(side/2)),(nhood_ctr(2)-floor(side/2)):(nhood_ctr(2)+floor(side/2)))
>
> % what is happening in this last line?
You're defining a new image 'nhood' that is a small square neighborhood with side lengths 'side' centered at nhood_ctr. Side, and nhood_ctr were chosen randomly for this example.

>
> WORKSPACE OUTPUT
>
> nhood =
>
> 234 236 251 234 239 227 240 241 245 225 251 234 228 250 232
> 248 245 236 238 246 247 246 234 242 238 239 246 235 245 238
> 245 223 0 251 233 230 246 244 231 251 230 240 249 238 232
> 241 245 251 235 233 238 237 237 247 250 240 226 240 244 245
> 230 239 226 251 251 238 246 241 242 223 251 251 228 238 231
> 246 251 231 232 236 223 251 237 230 251 232 0 244 248 240
> 235 237 246 242 251 244 242 230 242 235 246 237 237 246 239
> 242 234 240 238 236 239 234 246 237 241 229 251 235 241 238
> 240 240 250 234 230 251 224 246 240 240 240 240 240 240 240
> 232 237 230 245 0 221 251 225 240 240 240 240 240 240 240
> 243 243 251 226 251 247 228 244 240 240 240 240 240 240 240
> 242 223 227 235 238 247 231 247 240 240 240 240 240 240 240
> 222 242 251 228 248 237 235 235 240 240 240 240 240 240 240
> 251 230 229 245 230 238 243 237 240 240 240 240 240 240 240
> 224 234 251 248 235 238 251 231 240 240 240 240 240 240 240
>
> i believe this is my complete image......now how do i move around this neighborhoods?
>
> and how do i apply my filters to remove noise from this?
>
> thanks alot

This is not your image it is a 15x15 neighborhood of your image centered at pixel [200 200].
To move this around you would use nested for loops on nhood_ctr.
e.g.
I2 = zeros(size(I))
for i = 8:200
          for j = 8:200
                  nhood_ctr = [i j]; %You would probably skip defining this and just run you indices from i, j.
               nhood = I((nhood_ctr(1)-floor(side/2)):(nhood_ctr(1)+floor(side/2)),(nhood_ctr(2)-floor(side/2)):(nhood_ctr(2)+floor(side/2)));
                  I2(i, j) = my_fun(nhood);
        end
end
As for the filters, you'll have to define my_fun. By trying different 'side' sizes and functions figure out what works best for your image.

I would also recommend reading a book on introductory Matlab. See the indexing section.

Tags for this Thread

No tags are associated with 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