Test data generation for neural network handwriting recognition Can someone share some Octave/Matlab code or algorithm to pre-process a photo taken from mobile camera of a handwritten digit. 
After pre-processing, the data should have similar characteristics to the MNIST data set digit images. 
I have a neural network trained using the MNIST data set. Now I want to test my implementation by taking handwritten digit images using a phone camera and saving it on my computer. 
I want to give this image as input to test my neural net implementation. 
Thanks in advance !!
 A: When people train a model using a dataset, they split the data into several parts and do cross-validation: http://en.wikipedia.org/wiki/Cross-validation_(statistics)
If you scientifically want to find out the exact test performance of the model, you see on which portion of the data it is trained on, and test on the remaining. 
A: There might be something in the Octave forge image package that you could use or adapt to your purposes.
A: Actually, this is an old topic to answer, but somebody else may need similar code. Here is a MATLAB code that I wrote for my application. It is a bit messy, so I will explain it in general.
subject_list = {'X','Y'};

output = cell(1,size(subject_list,2)*30);
for subject = 1:size(subject_list,2)
    uncropped = rgb2gray(imread([subject_list{subject},'.jpg']));
    bw = imcomplement(im2bw(uncropped));
    se = strel('disk',10);
    bw_closed = imclose(bw,se);
    [L,n]= bwlabel(bw_closed);
    stats = regionprops(L);
    mean_array(subject) = mean([stats.Area]);
    mr = 22; mc = 22;
    numbers = cell(1,n);
    for i = 1:n
        if((stats(i).Area > 300) && (stats(i).Area < 3000))
            bs = stats(i).BoundingBox;
            numbers{i}(:,:) = imcomplement(uncropped(round(bs(2)-mr):round(bs(2)+bs(4)+mr),...
                round(bs(1)-mc):round(bs(1)+bs(3)+mc)));
        end
    end
    
    numbers(cellfun(@isempty,numbers))= [];
    
    for i = 1:size(numbers,2)
        output{1,30*(subject-1)+i} = numbers{i} ;
    end
end


MNIST_centmean = [14.9475,15.0064];

for num = 1:size(output,2)
    sample = imresize(im2double(output{num}),[28 28]);
    rp = regionprops(logical(im2bw(sample,0.1)));
    sample_tr = imtranslate(sample,[MNIST_centmean(1) - rp(1).Centroid(1),...
        MNIST_centmean(2)- rp(1).Centroid(2)]);
    sample_tr(sample_tr<=0.05) = 0;
    imwrite(sample_tr,['n_',int2str(num),'.png'],'PNG');
    resized_numbers(num,:) = reshape(sample_tr,[784,1]);
end

There are two subjects in subject_list each has 30 digits.

*

*read the subject.jpg with imread convert it to grayscale apply
some morphological operation with imclose (this is because some
digits may not be continous body like 5 or 9 for some subjects)


*label    each digit with bwlabel and find their properties with
regionprops (this step is necassary to locate where the digits are)


*take structures which has area between 300 & 3000 that correspond to
digit size in my case. It depends on resolution of the input image.


*discard empthy cells by usign cellfun
at the second part


*Resize each pacth to 28 x 28 with imresize with default bicubic interpolation.


*Translate the center of each pacthes to resemble it into MNIST dataset by using imtranslate. Assign the values to 0 which smaller then 0.05 . (bicubic interpolation added an offset to background which is not the case in MNIST)


*Reshaped the patches to 784x1 and stored them into a matrix (this is
default size for NN trained with MNIST)
