decreasing number of gray levels in a image

4 ビュー (過去 30 日間)
k.v.swamy
k.v.swamy 2012 年 11 月 30 日
コメント済み: Walter Roberson 2022 年 9 月 21 日
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.

回答 (1 件)

Image Analyst
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
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
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by