Write a (for loop ) function in Matlab for reducing the intensity level quantiza
ID: 3882647 • Letter: W
Question
Write a (for loop ) function in Matlab for reducing the intensity level quantization from 8 bits to 7 bits, 6bits ...1 bit.
the original image is 512x512.
Explanation / Answer
function result_im = ChangeBitDepthGrayImage(gray_im, desired_bit_depth) if (desired_bit_depth < 1) disp('converting to binary(1 bit) image'); desired_bit_depth = 1; end if (desired_bit_depth > 8) disp('converting to 8 bit image'); desired_bit_depth = 8; end %assuming we start with 8 bit image 256 levels num_levels = 2 ^ desired_bit_depth; %figures out how big each range should be, we use +1 because if we %divide the data into N levels, there should be N+1 boundaries limits = linspace(0,256,num_levels + 1); result_im = uint8(zeros(size(gray_im))); for i = 1:num_levels lower_lim = limits(i); upper_lim = limits(i+1); %creates a binary mask of values between the limits, the output is %0 or 1, but we need to make it uint8 for the next step temp_mask = uint8((gray_im >= lower_lim) & (gray_imRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.