Find surrounding and outer pixels

Hi,
I have used a 16x16 window to scan an entire image in matlab. The value of the largest pixel is stored as well as its position on the image.
I need to find the pixels surrounding the largest pixels and check if they are as bright as it. I also need to find the outer pixels and check if they are darker than the largest pixel.
Could anyone tell me how to find the surrounding pixels and the outer pixels?
Thanks.

Answers (1)

What do you mean by largest pixel? All pixels are the same size, aren't they? Do you mean brightest? You can find the brightest pixel in a neighborhood in two ways, depending on exactly how you define brightest: imregionalmax() and imdilate(). You can cast that image to double and subtract it from the original image to see how a pixel differs from the neighborhood.

6 Comments

Yes i mean the brightest. I have already found the brigtest pixel in the 16x16 neighbourhood. Then for each of the brigtest pixels found I need to check their surrounding pixels to check if it is as bright as that pixel. Do I need to use a 3x3 neighbourhood?
This is the code I have to find the brightest pixel in the 16x16 window
N = 16;
info = repmat(struct, ceil(size(Z, 1) / N), ceil(size(Z, 2) / N)); %creates an array of structs consisting of an m-by-n tiling
for row = 1:N:size(Z, 1)%loop through each pixel in the image matrix
for col = 1:N:size(Z, 2)
r = (row - 1) / N + 1;% store the row index for each window
c = (col - 1) / N + 1;%store the col index for each window
imgWindow = Z(row:min(end,row+N-1), col:min(end,col+N-1));
largest = max(imgWindow(:));
[rLarg, cLarg] = find(imgWindow == largest, 1, 'first');
window(r, c).largest = largest;
window(r, c).row = rLarg + row - 1;
window(r, c).col = cLarg + col - 1;
end
end
This would be my code
outputImage = imdilate(Z, true(17));
This is not what I am trying to do. I do not need a new image.
I need to know how to find the neighbours of the largest pixel.
maxValue = max(grayImage(:))
[row, col] = find(grayImage == maxValue, 1, 'first');
neighbors = [grayImage(row, col),...
grayImage(row-1, col-1),...
grayImage(row-1, col),...
grayImage(row-1, col),...
grayImage(row, col-1),...
grayImage(row, col+1),...
grayImage(row+1, col-1),...
grayImage(row+1, col),...
grayImage(row+1, col+1)];
Did this answer your question Ciara?
Hi,
I thanks for this info. I was using part of your code to find the 3x3 neireast matrix.
And now I am tryying to find the neareast number and its id betweeen two different size arrays?
for instance, I have an array: A: 540x1 values; and another array B, 540 X 4860 consisted of 540 blocks (each one represented by 3x3 matrix-so 9X540=4860).
What I want to do is to search through each of these 9 area block numbers, compare it with single number from B and retrieve that area.
A: 45 etc X 540
B: 5 6 9
4 15 16
21 55 2
etc X 540 blocks like this;
result: would be 55 and id=8 since the counting in my code goes like:
234
516
789
for instance if I give some fix row and col: eg row=15 and col=12 I get a good result with:
[value,index]=min(abs(neighbors_area(:)-100));
but when I want to do for the whole data set, there is an error that matrix sizes doesnt match.
Any clue?
Thanks

Sign in to comment.

Asked:

on 4 Apr 2014

Commented:

on 7 Feb 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!