How to reduce grayscale levels ?
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
1 개 추천
I have an RGB image, converted it into Grayscale image X = imread('lena.bmp'); Y = rgb2gray(X); now the image is represented by 8 bits (256 levels) and i want to quantize this image "Y" by reducing the grayscale levels to 32 (5 bits), how to do that ?
i know i can show the image like this imshow(Y,colormap(gray(32))); but that will just show the image with 32 levels and i want to save it in a variable not just showing it off
채택된 답변
Image Analyst
2015년 4월 27일
Use imquantize() or just divide the image by 8.
Y32 = Y / 8;
댓글 수: 10
Mohab Mostafa
2015년 4월 27일
and what if i want 64 levels ?
Image Analyst
2015년 4월 27일
For powers of 2 you can just divide by the number, so for 64 gray levels you would divide by 256/64 = 4. For 64 gray levels divide by 8, etc. If you want those gray levels spread over the entire range, then you need to multiply them by the number after dividing them. The division will truncate the fraction so you won't end up with the same values. Or if you have some non-power-of-2 number and want to specify the output levels, use imquantize() - it's much more general. If this answers the question, can you officially "Accept" it? Thanks in advance.
Mohab Mostafa
2015년 4월 28일
Honestly, it's not clear. you said * For powers of 2 you can just divide by the number, so for 64 gray levels you would divide by 256/64 = 4. For 64 gray levels divide by 8 * how come to divide by 4 for 64 levels, and at the same time divide by 8 also for 64 levels !! i need example please, i have a matrix (which is the grayscale image with 256 levels) and i want to quantize it by 32 levels (5 Bit "2^5")..is it as simple as dividing by 32 ? (Y32 = Y/32) ?? or what ?
Yes, it's that simple. Let's take a simple example of an 8 bit array being converted into numbers that are no more than 5 "1" bits.
Y = uint8([1, 3, 17, 42, 75, 166])
% Turn into numbers that can be represented in 5 bits.
% 5 bits means the max intensity would be 31
% Let's illustrate that by dividing by 256/2^5 = 8 = 2^3:
dec2hex(31) % Shows 1F which is 5 bits.
% Now do for our example.
Y8 = Y / 8 % shows 0 0 2 5 9 21
Of course Y8 is still a uint8 variable since there are no 2, 3, 4, 5, 6, or 7 bit variables, but the values can be expressed in no more than 3 bits.
Mohab Mostafa
2015년 4월 29일
just to make sure i got it, for 64 levels (6 bits) Y64 = Y / (256/2^6), for 32 levels (5 bits) Y32 = Y / (256/2^5), for 16 levels (4 bits) Y16 = Y / (256/2^4),...etc. is that correct ?
Image Analyst
2015년 4월 29일
No. Look at the examples I gave. You divide by 2 to the 8 minus the number of bits you want, so y64 = y / (256/2^(8-6)).
To make it clear
256 2^8 8bit
128 2^7 7bit
64 2^6 6bit
32 2^5 5bit
16 2^4 4bit
8 2^3 3bit
4 2^2 2bit
2 2^1 1bit
Mohab Mostafa
2015년 4월 29일
Ok great, Thank you very much
soe
2018년 1월 4일
For image Y, to convert from 256 levels to 32 levels, the values should be 0 to 31. But Y/8 may be 0 to 32. (e.g. 255/8 = 31.875 becomes 32). So, how can i solve this problem?
Use floor():
y8 = uint8(floor(double(y)/8))
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Blue에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
