decreasing number of gray levels in a image
조회 수: 4 (최근 30일)
이전 댓글 표시
hi all, can any one tell me how to decrease the no of gray levels in a image.i have to decrease in the powers of 2. regards k.v.swamy.
댓글 수: 0
답변 (1개)
Image Analyst
2012년 11월 30일
Perhaps I don't understand what you want, but why can't you simply divide the image by 2, 4, 8, or whatever power of 2 you want? For examples:
reducedGrayLevelsImage = originalGrayImage / 8;
reducedGrayLevelsImage = originalGrayImage / 16;
reducedGrayLevelsImage = originalGrayImage / 4;
Is that all you're looking for? Or is it more complicated than that? If so, explain the nuances that I've overlooked.
댓글 수: 2
knight
2022년 9월 21일
How do we reduce graylevel when the desired number of gray levels does not have to be a power of 2?
Walter Roberson
2022년 9월 21일
There are two different possible interpretations here.
If you want to reduce your image from 256 levels to N levels, and you want those N levels to be uint8 0, 1, 2, .. N-1 then
reducedImage = uint8(rescale(double(YourImage), [0 N-1], 'InputMin', 0, 'InputMax', 255));
or
thresh = multithresh(YourImage, N);
reducedImage = imquantize(YourImage, thresh);
or
thresh = linspace(0, 255, N);
reducedImage = imquantize(YourImage, thresh); %might need adjustment
But sometimes you want to keep the range of values but have fewer distinct values.
thresh = multithresh(YourImage, N);
reducedImage = imquantize(YourImage, thresh, [0 thresh(2:end) 255]);
or
thresh = linspace(0, 255, N);
reducedImage = imquantize(YourImage, thresh, [0 thresh(2:end) 255]); %might need adjustment
The versions that use multithresh dynamically calculate grayscale levels, possibly unevenly -- for example if you had three coins with different grayscale levels then it could pick them out.
The versions that use linspace calculate grayscale levels evenly.
The version that uses rescale() calculates grayscale levels evenly.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!