pixel by pixel squaring of image?

5 visualizzazioni (ultimi 30 giorni)
RAVI  KUMAR
RAVI KUMAR il 12 Ago 2016
Commentato: Image Analyst il 22 Nov 2019
If I have an image of size M by N then how can I do the square of each pixel individually?

Risposte (1)

Sabarinathan Vadivelu
Sabarinathan Vadivelu il 12 Ago 2016
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 Commenti
maaham banu
maaham banu il 22 Nov 2019
hi, why doesnt this algorithm work for a gray image? I am getting only 255
Image Analyst
Image Analyst il 22 Nov 2019
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()

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by