Image Normalization in the range 0 to 1
이전 댓글 표시
채택된 답변
추가 답변 (3개)
mutant
2019년 10월 6일
Old question but as of R2017b, rescale does exactly this.
B = rescale(A); % Normalizes image (0 to 1, by default)
You can even use this to scale to uint8, for example:
B = rescale(A,0,255); % Normalizes image to [0 255]
Documentation here:
Azzi Abdelmalek
2013년 12월 12일
편집: Azzi Abdelmalek
2013년 12월 12일
If im is your image
im=(im-min(im(:)))/(max(im(:))-min(im(:)))
댓글 수: 1
Jos (10584)
2013년 12월 12일
I suggest to do this in two steps to avoid the calculation of MIN twice ...
IM = IM - min(IM(:)) ;
IM = IM / max(IM(:)) ;
Sajid Khan
2014년 2월 6일
편집: DGM
2023년 2월 13일
function image_normalized = imnormalize( image_orig, min_norm, max_norm)
val_max = max(image_orig(:));
val_min = min(image_orig(:));
range = val_max - val_min;
image_normalized = (image_orig - val_min) ./ range; % Then scale to [x,y] via:
range2 = max_norm - min_norm;
image_normalized = (image_normalized*range2) + min_norm;
end
In this function, you can set min_norm = 0 and max_norm = 1 to normalize image to a scale of 0 to 1. If you have any other questions to ask, then you are welcome. I always use this function for normalization purpose. It even works if you have to increase the scale length.
댓글 수: 2
Image Analyst
2014년 2월 6일
Your function basically does the same thing as the built in function mat2gray().
DGM
2023년 2월 13일
Rather, mat2gray() only allows the specification of the input levels, assuming the output levels are [0 1]. Sajid's function allows specification of the output levels, while using image extrema as the input levels.
So in that sense, it's more like rescale(), same syntax and everything.
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!