To find the centeral pixel of coloured image ... ?

조회 수: 4 (최근 30일)
jagkaran
jagkaran 2011년 10월 30일
i want to find the centeral pixel of a nxn window of a colored image of size 512x512 ...
say, i want to make a matrix of 3x3 and so 5x5 and so on to find out the centeral pixel within that window ...
is there any method or command to find out ???

답변 (3개)

Image Analyst
Image Analyst 2011년 10월 31일
So ambigous. What is "matrix"? Is that "window" or is that "image"? If you have an image, and you have a location (row, column) where the n-by-n window is centered (with n being odd such as 3, 5, or 7) then the center pixel is located at (row, column) and it does not depend on the window size. For example a window located at row=100, column=200 and width 3 will cover rows going from 99 to 101 and 199 to 201, but the center is still at 100, 200 regardless of what the window size is. The color values can be extracted like this:
redValue = rgbImage(row, column, 1);
greenValue = rgbImage(row, column, 2);
blueValue = rgbImage(row, column, 3);
  댓글 수: 1
jagkaran
jagkaran 2011년 11월 8일
the colour components u have told ... that i have already understood ... i want to know the method to find the centeral pixel ...

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 10월 31일
blockproc() or (for older systems) blkproc()
Also, I am by no means certain, but I think you might be able to do it for odd-sized n x n windows as:
mask = zeros(n); mask(ceil(numel(mask)/2)) = 1;
conv2(YourImage, mask)
I think that you will find that in practice the output looks almost exactly like YourImage...
  댓글 수: 2
jagkaran
jagkaran 2011년 11월 8일
what does this numel denotes ...?
Image Analyst
Image Analyst 2011년 11월 8일
Have you looked in the help? Apparently not because it's right in there. It's one of the main functions of MATLAB. You should really learn to use the help before asking people, especially for functions that are right in there.

댓글을 달려면 로그인하십시오.


Walter Roberson
Walter Roberson 2011년 11월 8일
If you have a 3 x 3 mask, the central pixel is at index (2,2), which is ( (3+1)/2, (3+1)/2 ). Index (2,2) inside a 3 x 3 matrix is at MATLAB absolute index position 5, which is (3*3 + 1)/2
If you have a 5 x 5 mask, the central pixel is at index (3,3), which is ( (5+1)/2, (5+1)/2 ). Index (3,3) inside a 5 x 5 matrix is at MATLAB absolute index position 13, which is (5*5 + 1)/2
In general, for an n x n mask, the central pixel is at index ( (n+1)/2, (n+1)/2 ), which is at MATLAB absolute index (n * n + 1)/2
So now you know how to find the central pixel of an square matrix with odd-numbered dimensions.
Not very exciting at all. And if you use a sliding window technique with overlaps, extracting the central pixel each time will be exactly the same as the original image (except perhaps with the border cropped).

Community Treasure Hunt

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

Start Hunting!

Translated by