Commits

Zoltán Szabó committed d84da35

Different noisy examples added to image registration; see 'quick_test_Himreg.m', 'quick_test_Iimreg.m', 'add_image_noise.m'.

  • Participants
  • Parent commits 86efb5c

Comments (0)

Files changed (4)

File CHANGELOG.txt

+-Different noisy examples added to image registration; see 'quick_test_Himreg.m', 'quick_test_Iimreg.m', 'add_image_noise.m'.
+
 v0.49 (Dec 1, 2013):
 
 New:

File code/estimators/quick_tests/quick_test_Himreg.m

     num_of_rots = 21; %number of rotations examined
     h = 0; %feature representation of an image = neighborhoods around the pixels of the image; neigbourhood: (2h+1)x(2h+1); h=0 <-> pixels 
     S0 = 101; %resize the original image to S0 x S0
+    %noise parameters (see 'add_image_noise.m'):
+        %I (no noise):
+            %noise.name = 'no';
+        %II (each pixel is 'flipped' with probability 'p'):
+            noise.name = 'flip'; noise.p = 0.3;
+        %III (noisy image = edge filtered version of the original one):
+            %explicitly specify noise.threshold:
+                %noise.name = 'sobel'; noise.threshold = 10/255;
+            %noise.threshold is chosen automatically:    
+                %noise.name = 'sobel';
     %method used to measure the similarity of 2 images (estimators of 'd=1' type do not directly cope with the problem):
         %base:
             cost_name = 'Shannon_kNN_k';     %h>=0
     S = floor(S0/sqrt(2)); %maximal size that fits to an S0xS0 sized image under any rotation
     %target image:
         I_target_large = load('lena512.mat');%512x512
-        I_target_large = imresize(I_target_large.lena512,[S0,S0]);
+        I_target_large = imresize(I_target_large.lena512,[S0,S0])/255;%'/255': [0,255] -> '[0,1]';
         I_target_center = im_cut(I_target_large,S,S); %SxS
         %features of I_target_center:
             I_target_center_f = im2col(I_target_center,[2*h+1,2*h+1],'sliding');
+    %add noise:
+        figure;            
+            subplot(2,1,1); imshow(I_target_center,[]); title('original image');
+            I_target_large = add_image_noise(I_target_large,noise);
+            subplot(2,1,2); imshow(im_cut(I_target_large,S,S),[]); title('noisy image to be registered (unrotated)');
     co = H_initialization(cost_name,1);
     %explicitly set the kNN method and its parameters:
         %co = H_initialization(cost_name,1,{'kNNmethod', 'ANN', 'k', 3, 'epsi', 0});
     end
     
 %plot:
+    figure;
     plot(rotations,sim_hat);
     xlabel('Angle of rotation');
     ylabel('Estimated similarity: entropy');

File code/estimators/quick_tests/quick_test_Iimreg.m

     num_of_rots = 21; %number of rotations examined
     h = 0; %feature representation of an image = neighborhoods around the pixels of the image; neigbourhood: (2h+1)x(2h+1); h=0 <-> pixels 
     S0 = 101; %resize the original image to S0 x S0
+    %noise parameters (see 'add_image_noise.m'):
+        %I (no noise):
+            %noise.name = 'no';
+        %II (each pixel is 'flipped' with probability 'p'):
+            noise.name = 'flip'; noise.p = 0.3;
+        %III (noisy image = edge filtered version of the original one):
+            %explicitly specify noise.threshold:
+                %noise.name = 'sobel'; noise.threshold = 10/255;
+            %noise.threshold is chosen automatically:    
+                %noise.name = 'sobel';
     %method used to measure the similarity of 2 images (estimators of 'd=1' type do not directly cope with the problem):
         %base:
             cost_name = 'GV';   %h>=0
     S = floor(S0/sqrt(2)); %maximal size that fits to an S0xS0 sized image under any rotation
     %target image:
         I_target_large = load('lena512.mat');%512x512
-        I_target_large = imresize(I_target_large.lena512,[S0,S0]);
+        I_target_large = imresize(I_target_large.lena512,[S0,S0])/255;%'/255': [0,255] -> '[0,1]'
         I_target_center = im_cut(I_target_large,S,S); %SxS
         %features of I_target_center:
             I_target_center_f = im2col(I_target_center,[2*h+1,2*h+1],'sliding');
+    %add noise:
+        figure;            
+            subplot(2,1,1); imshow(I_target_center,[]); title('original image');
+            I_target_large = add_image_noise(I_target_large,noise);
+            subplot(2,1,2); imshow(im_cut(I_target_large,S,S),[]); title('noisy image to be registered (unrotated)');
     co = I_initialization(cost_name,1);
     sim_hat = zeros(length(rotations),1); %vector of estimated similarities
     nrot = 1; %rotation index
                 I_transformed_center_f = im2col(I_transformed_center,[2*h+1,2*h+1],'sliding');
         %similarity(I_target_center,I_transformed_center):
             sim_hat(nrot) = I_estimation([I_target_center_f;I_transformed_center_f],ds,co); %mutual information of the feature representations of the images
+            %sim_hat(nrot) = mean(sum((I_target_center_f-I_transformed_center_f).^2));%
         %disp:
             disp(strcat(['rotation index: ',num2str(nrot),'/',num2str(num_of_rots)]));
             nrot = nrot + 1;
     end
     
 %plot:
+    figure;
     plot(rotations,sim_hat);    
     xlabel('Angle of rotation');
     ylabel('Estimated similarity: mutual information');

File code/estimators/quick_tests/utilities/add_image_noise.m

+function [I2] = add_image_noise(I1,noise)
+%function [I2] = add_image_noise(I1,noise)
+%Adds noise to image I1; the result is I2.
+%
+%INPUT: 
+%   noise : structure describing the image noise, possibilities:
+%      noise.name = 'no'  : no noise, i.e., I2 = I1;
+%      noise.name = 'flip': with probability noise.p each pixel of I1 is changed to 255 minus the pixel value.
+%      noise.name = 'sobel'; edge-filtered (sobel) image, noise.threshold is chosen automatically
+%      noise.name = 'sobel': noise.threshold = 10; edge-filtered (sobel) image, explicitly specify noise.threshold.
+                
+%Copyright (C) 2013 Zoltan Szabo ("http://www.gatsby.ucl.ac.uk/~szabo/", "zoltan (dot) szabo (at) gatsby (dot) ucl (dot) ac (dot) uk")
+%
+%This file is part of the ITE (Information Theoretical Estimators) Matlab/Octave toolbox.
+%
+%ITE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
+%the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+%
+%This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+%
+%You should have received a copy of the GNU General Public License along with ITE. If not, see <http://www.gnu.org/licenses/>.
+
+value_max = 1;
+
+switch noise.name 
+    case 'no' %no noise
+        I2 = I1;
+    case 'flip' %P(i->1-i)=p, P(i->i)=1-p
+        p = noise.p;
+        mask = (rand(size(I1)) < p); 
+        I2 = value_max*mask - 2 * (mask-1/2) .* I1;
+    case 'sobel' %edge filtered image
+        if any(strcmp('threshold',fieldnames(noise))) %noise.threshold: exists
+            I2 = edge(I1,'sobel',noise.threshold);
+        else
+            I2 = edge(I1,'sobel');
+        end
+    otherwise
+        error('Noise=?');
+end
+