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
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Clustering에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!