Converting 32 bit to uint16
I want to convert 32bit image to uint16 image but preserve the grey values. I do not want to lose the grey value, rather scale them to the uint16. How can I do this. My code below makes the images fully grey.
% Normalize the pixel values to the range [0, 1]
img_normalized = double(img_original) / double(max(img_original(:)));
% Find the minimum and maximum values in the normalized image
min_val = min(img_normalized(:));
max_val = max(img_normalized(:));
% Define the minimum and maximum values for uint16
min_uint16 = double(intmin(‘uint16’));
max_uint16 = double(intmax(‘uint16’));
% Calculate the scaling factors
scale_factor = (max_uint16 – min_uint16) / (max_val – min_val);
% Scale the pixel values to uint16 range
img_scaled = uint16((img_normalized – min_val) * scale_factor + min_uint16);I want to convert 32bit image to uint16 image but preserve the grey values. I do not want to lose the grey value, rather scale them to the uint16. How can I do this. My code below makes the images fully grey.
% Normalize the pixel values to the range [0, 1]
img_normalized = double(img_original) / double(max(img_original(:)));
% Find the minimum and maximum values in the normalized image
min_val = min(img_normalized(:));
max_val = max(img_normalized(:));
% Define the minimum and maximum values for uint16
min_uint16 = double(intmin(‘uint16’));
max_uint16 = double(intmax(‘uint16’));
% Calculate the scaling factors
scale_factor = (max_uint16 – min_uint16) / (max_val – min_val);
% Scale the pixel values to uint16 range
img_scaled = uint16((img_normalized – min_val) * scale_factor + min_uint16); I want to convert 32bit image to uint16 image but preserve the grey values. I do not want to lose the grey value, rather scale them to the uint16. How can I do this. My code below makes the images fully grey.
% Normalize the pixel values to the range [0, 1]
img_normalized = double(img_original) / double(max(img_original(:)));
% Find the minimum and maximum values in the normalized image
min_val = min(img_normalized(:));
max_val = max(img_normalized(:));
% Define the minimum and maximum values for uint16
min_uint16 = double(intmin(‘uint16’));
max_uint16 = double(intmax(‘uint16’));
% Calculate the scaling factors
scale_factor = (max_uint16 – min_uint16) / (max_val – min_val);
% Scale the pixel values to uint16 range
img_scaled = uint16((img_normalized – min_val) * scale_factor + min_uint16); convert 32bits to 16bits MATLAB Answers — New Questions