I have the following code, which I am trying to normalize my images after filtering but the problem is that as soon as it get to line 5, it change everyting to 0 and it returns me black images. any idea ?
for i=1:10
temp_imag = imag_test1{i}(:,:);
t_max = max(max(temp_imag));
t_min = min(min(temp_imag));
temp_imag = (temp_imag-t_min).*double(((new_max-new_min)/(t_max-t_min)))+double(new_min);
imag_test1{i}(:,:) = temp_imag;
end
You don’t tell which values
new_maxandnew_minget, but anyway if every after line 5 (temp_imag = (temp_imag-t_min).*double(((new_max-new_min)/(t_max-t_min)))+double(new_min);
) everything becomes zero, there are a few possibilities:imga_test{i}(1 <= i <= 10) are all zeros andnew_minis also zero. Have you checked the value ofimga_testthat they are not all zeros and that they vary? You can create example data forimga_testeg. by usingrandorrandi. If random data gives you non-zeros, the problem is inimga_test.new_max-new_minis zero, which means thatnew_maxandnew_minhave same value. Have you tried changing values fornew_maxandnew_minand changing their difference? If changing the values ofnew_max,new_minor both gives you non-zeros, the problem is innew_maxandnew_min.By using
solveto solve the equation eg. fornew_min:solve('temp_imag = (temp_imag-t_min)*(((new_max-new_min)/(t_max-t_min)))+(new_min)', 'new_min'):ans =(new_max*t_min - new_max*temp_imag - t_min*temp_imag + t_max*temp_imag)/(t_max - temp_imag)
This third case is very improbable.