To find the centeral pixel of coloured image ... ?
2 次查看(过去 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 ???
0 个评论
回答(3 个)
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);
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 个评论
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
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).
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!