简体   繁体   中英

Matlab image normalization after filtering

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_max and new_min get, 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:

  1. imga_test{i} ( 1 <= i <= 10 ) are all zeros and new_min is also zero. Have you checked the value of imga_test that they are not all zeros and that they vary? You can create example data for imga_test eg. by using rand or randi . If random data gives you non-zeros, the problem is in imga_test .

  2. new_max-new_min is zero, which means that new_max and new_min have same value. Have you tried changing values for new_max and new_min and changing their difference? If changing the values of new_max , new_min or both gives you non-zeros, the problem is in new_max and new_min .

  3. By using solve to solve the equation eg. for new_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.

I would try presenting the pre vs post processed image:

figure();
for i=1:10     
     temp_imag = imag_test1{i}(:,:);
     subplot( 1, 2, 1 ); imshow( temp_imag, [] ); title( 'pre' ); 
     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);
     subplot( 1, 2, 2 ); imshow( temp_imag, [] );  title( 'post' );    
     imag_test1{i}(:,:) = temp_imag;
 end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM