Clear Filters
Clear Filters

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

3 views (last 30 days)
jagkaran
jagkaran on 30 Oct 2011
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 ???

Answers (3)

Image Analyst
Image Analyst on 31 Oct 2011
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 Comment
jagkaran
jagkaran on 8 Nov 2011
the colour components u have told ... that i have already understood ... i want to know the method to find the centeral pixel ...

Sign in to comment.


Walter Roberson
Walter Roberson on 31 Oct 2011
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 Comments
jagkaran
jagkaran on 8 Nov 2011
what does this numel denotes ...?
Image Analyst
Image Analyst on 8 Nov 2011
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.

Sign in to comment.


Walter Roberson
Walter Roberson on 8 Nov 2011
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).

Categories

Find more on Data Clustering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!