decreasing number of gray levels in a image
6 次查看(过去 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!