# how to create a loop to calculate the mean of pixels of satellite data of a specified area like india? pixe size of the data is 1440*720

3 views (last 30 days)
Jincy on 15 May 2023
Commented: Dyuman Joshi on 15 May 2023
% Load or create an image
image = imread('your_image.jpg'); % Replace with your image file name or path
% Determine image size
[rows, columns, ~] = size(image);
% Variables to store sum and count
sumPixels = 0;
countPixels = 0;
% Loop to calculate sum of pixel values and count
for row = 1:rows
for col = 1:columns
% Access pixel value
pixelValue = image(row, col);
sumPixels = sumPixels + pixelValue;
% Increment count
countPixels = countPixels + 1;
end
end
% Calculate mean
meanPixels = sumPixels / countPixels;
Dyuman Joshi on 15 May 2023
What seems to be the problem in your approach?

Shaik on 15 May 2023
Hey, check this once
% Load or create an image
image = imread('your_image.jpg'); % Replace with your image file name or path
% Define the region of interest (India)
startRow = 200; % Starting row index of the ROI
endRow = 600; % Ending row index of the ROI
startCol = 500; % Starting column index of the ROI
endCol = 900; % Ending column index of the ROI
% Variables to store sum and count
sumPixels = 0;
countPixels = 0;
% Loop to calculate sum of pixel values and count within the ROI
for row = startRow:endRow
for col = startCol:endCol
% Access pixel value
pixelValue = image(row, col);
sumPixels = sumPixels + pixelValue;
% Increment count
countPixels = countPixels + 1;
end
end
% Calculate mean
meanPixels = sumPixels / countPixels;

### Categories

Find more on Image Processing and Computer Vision 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!