I = imread('img.jpg'); I = (double(I).^3) The problem is, when I do operations like I.^3, pixels go far away from 255 value. I need them to be in range 0 - 255, and be able to multiply image to any value, without exceeding range. Anyone got idea how could I do it?
Prashant Kumar answered .
2025-11-20
You could use mat2gray() to map the min to 0 and the max to 1.
I = mat2gray(I);
Multiply by 255 if you want in the range 0-255 and cast to uint8 if you want
I = uint8(255 * mat2gray(I));
I would recommend using a more descriptive variable name than I. You don't want it to be mistaken for a 1 or an l, and you don't want your code to look like alphabet soup.