
function  [] = readInScanData(dirname, nameMethod)
    cd(dirname);
    dirNames = dir();
    for k=3:length(dirNames)
        dirName = dirNames(k).name;
        cd(dirName);
        allDicoms = dir();   
        name = allDicoms(3).name;
        firstImage = dicomread(name);
        meta = dicominfo(name);
        threeDImage = uint16(firstImage(:,:,1));
        threeDImage(end,end,80) = 0;
        for i = 1:length(allDicoms)
          name = allDicoms(i).name;
          if k == 3
            savenameResult = strcat('../results', nameMethod);  
%             fid = fopen(strcat(savenameResult, '.txt'), 'w') ;
%             %fmt = '%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n';
%             fprintf(fid, '%s ', 'StdSpheres, meanSpheres, stdBackground, meanBackground, skewnessBackground, kurtosisBackground, CoeffOfVarSpheres, CoeffOfVarBackground') ;
%             fprintf(fid, '\n');
%             fclose(fid) ;
%             savenameRC = strcat('../RC', nameMethod);
%             fidnames = fopen(strcat(savenameRC, '.txt'), 'w');
%             %fmtRC = '%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f\n';
%             fprintf(fidnames, '%s ', 'rC37, rc28, rc22, rc17, rc13, rc10');
%             fprintf(fidnames, '\n');
%             fclose(fidnames) ;
          end
          if length(name) >2
            image = uint16(dicomread(name));
            meta = dicominfo(name);
            image = image * meta.RescaleSlope + meta.RescaleIntercept;
            size0 = size(image);


            %threeDImage = zeros(size0(1), size0(2), 80);

            if(i>7 & i<89)
                actualImage =uint16(image);
                actualImage = setSpineToZero_05_1(actualImage);

                threeDImage(:,:,i-7) = actualImage;
    %             s = int2str(i);
    %             dicomwrite(threeDImage(:,:,i-7), strcat('test', s));                   

            end
          end
        end
        [sphereValues threeDImage recoveryCoeff] = getSpheres1_10(meta, threeDImage);
%          values =  getbackgroundAtCertainSlide(threeDImage, 58);
%              fig3 = figure;
% %             
%             set(gca,'XLim',[0 9000]);
%             set(gca,'YLim', [0 30]);
%             set(gca, 'XTick',[0:500:9000]);
%              Ctrs = [0:200:9000];
%             hist(values(values>0 & values<9000), Ctrs);
%             print(fig3,strcat('../scanHistAll',int2str(k)),'-dpng');
%             for i = 1:5
%                 actualValues = values(i,:);
%                %fig = figure;
%                %plot(actualValues(actualValues>0));
%                 s = int2str(i);
%                 sk = int2str(k);
%                 ik = strcat(s,sk);
%                 %print(fig,strcat('../scan',ik),'-dpng');
%                 fig2 = figure;
%                 
%                 set(gca,'XLim',[0 9000]);
%                 
%                 hist(actualValues(actualValues>0 & actualValues<10000), Ctrs);
%                 print(fig2,strcat('../scanHIst',ik),'-dpng');
%             end
%          plot(actualValues(actualValues>0)) 
%        % background1 = getBackground(threeDImage);
         background = getBackgroundPartsScan( threeDImage );
             
%             histname = strcat(name, 'hist');
% %             hist(background);
% %             print( histname, '-dpng')
%             
%             %savefig(h, histname);
%             %dlmwrite('../test.csv',headlineCSV, 'delimiter',' ');
            %dlmwrite('filenames.csv',name,'delimiter','','-append');
     
            writeDataToCSV(dirName, background, sphereValues, recoveryCoeff, nameMethod);
            cd(dirname);
    end
                         
end


