standard deviation image ( for each pixels)

16 views (last 30 days)
Goodmorning, I have a problem with the computing of a standard deviation of each pixel of a image.
I have an image of 680x4x626 (rows , bands and columns). I would like to calculate the standard deviation of each pixel to get a standard deviation image.
I found the stdfilt function but it doesn't seem to do what I need. Can you help me with this?
Till now, my code is :
LS_NIRv2 = squeeze(double(img1(:, 2, :))); to extract from img1 the second band ( which is an index)
NIRv_rad = reshape(LS_NIRv2,[],1); later, I reshape it to a vector for the next plots.

Accepted Answer

Jack
Jack on 3 Apr 2023
You can use the std function in MATLAB to calculate the standard deviation of each pixel along the band dimension. Here is the modified code:
% Load the image
img1 = imread('your_image_file.tif');
% Extract the second band
LS_NIRv2 = squeeze(double(img1(:, 2, :)));
% Calculate the standard deviation of each pixel along the band dimension
std_image = std(LS_NIRv2, [], 2);
% Reshape the standard deviation image to the original size
std_image = reshape(std_image, size(LS_NIRv2, 1), size(LS_NIRv2, 3));
% Display the standard deviation image
imagesc(std_image);
colorbar;
Here, the std function is applied along the second dimension (2) of the LS_NIRv2 matrix, which corresponds to the band dimension. The [] argument indicates that the standard deviation should be calculated over all elements in the band dimension. The resulting standard deviation vector is then reshaped to the original image size using the reshape function.
The resulting std_image matrix contains the standard deviation of each pixel along the band dimension. You can display this image using the imagesc function and add a colorbar to show the standard deviation values.

More Answers (0)

Categories

Find more on Images 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!