Compute Threshold value using Balanced histogram
6 ビュー (過去 30 日間)
古いコメントを表示
I want to compute balanced histogram threshodling value. The function I want to create must give an optimum value for threshold. I have adapted code from here The AI Learner which is basically in python but I converted it to MATLAB as follow:
However, the optimum value calculated is 234 which isn't accurate for the following attached histogram. Testing image lenna512_low_dynamic_range.bmp is also attached.
Any help would be appreciated.
clc;clear all; close all;
im_ldr=uint8(imread('lenna512_low_dynamic_range.bmp'));
subplot(2,2,1);
imshow(im_ldr);
title('Original Image');
subplot(2,2,2);
imhist(im_ldr);
title('Non-Equalized Histogram');
x = imhist(im_ldr);
i_s = find(x>0,1,'first');
i_e = find(x>0,1,'last');
i_m = (i_s + i_e)/2;
A = i_s:i_m;
w_l = sum(A);
B = i_m:i_e;
w_r = sum(B);
while i_s ~= i_e
if w_r > w_l
w_r = w_r - x(i_e);
if ((i_s + i_e)/2) < i_m
w_l = w_l - i_m;
w_r = w_r + i_m;
i_m = i_m-1;
end
else
w_l = w_l - i_s;
i_s = i_s + 1;
if ((i_s + i_e)/2) >= i_m;
w_l = w_l + i_m+1;
w_r = w_r - i_m+1;
i_m = i_m + 1;
end
end
end
2 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!