If I have an image of size M by N then how can I do the square of each pixel individually?

Antworten (1)

Sabarinathan Vadivelu
Sabarinathan Vadivelu am 12 Aug. 2016

1 Stimme

outImage = zeros(size(inputImage));
for i = 1 : size(inputImage, 1)
for j = 1 : size(inputImage, 2)
outImage(i, j) = inputImage(i,j)^2;
end
end

4 Kommentare

RAVI  KUMAR
RAVI KUMAR am 12 Aug. 2016
I have tried it but couldn't get the result. As if do the the square of each pixel first and then the square root of each pixel then I should get the initial input image but I didn't
RAVI  KUMAR
RAVI KUMAR am 12 Aug. 2016
It worked with using ones instead of zeros in the first line.. putImage = ones(size(inputImage));
Anyway thanks for the help.
maaham banu
maaham banu am 22 Nov. 2019
hi, why doesnt this algorithm work for a gray image? I am getting only 255
Because if the value goes above 255, it clips to 255. You'll have to use uint16 or double. And don't use a for loop like this answer did. Use dot caret instead:
outImage = double(inputImage) .^ 2; % or uint16()

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 12 Aug. 2016

Kommentiert:

am 22 Nov. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by