Azzera filtri
Azzera filtri

I need code urgently for my project to find average of pixels by considering 7 by 7 matrix

2 visualizzazioni (ultimi 30 giorni)
I want code for finding the mean by considering 7 by 7 matrix. For each pixel in the image i want to calculate 5 mean values. First mean should be calculated by placing the original pixel at the center of 7 by 7 matrix and the second,third,fourth and fifth mean should be calculated by placing the same pixel at top left,top right,bottom left,bottom right of the 7 by 7 matrix.
  3 Commenti

Accedi per commentare.

Risposte (2)

Walter Roberson
Walter Roberson il 28 Gen 2019
Use filter2()
The mask you pass to filter2 is applied with the pixel at the top left if I remember correctly. However can ask for the full results rather than 'valid' and you can extract subsets of the filtered results . MM(1:end-6,1:end-6), MM(7:end,1:end-6) and so on where MM is the output of filter2 .
  3 Commenti
viswanath reddy
viswanath reddy il 28 Gen 2019
I need to calculate 5 mean values of every pixel in an image. The first mean value should be calculated by assuming the pixel at the center of 7*7 window and the 2nd,3rd,4th and 5th mean values should be calculated by assuming that the same pixel is located at top left,top right,bottom left and bottom right corners of the 7*7 window.
Walter Roberson
Walter Roberson il 28 Gen 2019
you already said that in the same words. If I did not understand your question then you need to explain differently such as with an example .

Accedi per commentare.


Image Analyst
Image Analyst il 28 Gen 2019
Try this:
grayImage = imread('moon.tif'); % Whatever ...
% Shift pixel at upper left to middle.
kernel = zeros(7);
kernel(1,1) = 1;
upperLeft = imfilter(grayImage, kernel);
% imshow(upperLeft);
% Shift pixel at upper right to middle.
kernel = zeros(7);
kernel(1,3) = 1;
upperRight = imfilter(grayImage, kernel);
% imshow(upperRight);
% Shift pixel at lower left to middle.
kernel = zeros(7);
kernel(3,1) = 1;
lowerLeft = imfilter(grayImage, kernel);
% imshow(lowerLeft);
% Shift pixel at lower right to middle.
kernel = zeros(7);
kernel(3,3) = 1;
lowerRight = imfilter(grayImage, kernel);
% imshow(lowerRight);
But it's not really correct to call the pixel at the upper left of a 7x7 window a "mean" since it's just a single pixe,, not the average of multiple values.

Community Treasure Hunt

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

Start Hunting!

Translated by