I need code urgently for my project to find average of pixels by considering 7 by 7 matrix
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
Antworten (2)
Walter Roberson
am 28 Jan. 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 Kommentare
Walter Roberson
am 28 Jan. 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 .
Image Analyst
am 28 Jan. 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.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!