Compute Threshold value using Balanced histogram
Mostra commenti meno recenti
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 Commenti
Image Analyst
il 23 Lug 2021
Why did you not do line 18 of the example?
Adnan Khan
il 23 Lug 2021
Risposte (0)
Categorie
Scopri di più su Contrast Adjustment in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!