[40] | 1 | % relabel_i_j: relabel an image series with two indices, according to the time matrix given by ImaDoc
|
---|
| 2 | %----------------------------------------------------------------------
|
---|
| 3 | function GUI_input=relabel_i_j(num_i1,num_i2,num_j1,num_j2,Series)
|
---|
| 4 | %requests for the visibility of input windows in the GUI series (activated directly by the selection in the menu ACTION)
|
---|
| 5 | if ~exist('num_i1','var')
|
---|
| 6 | GUI_input={};
|
---|
| 7 | return %exit the function
|
---|
| 8 | end
|
---|
| 9 |
|
---|
| 10 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%enable waitbar
|
---|
| 11 | hseries=guidata(Series.hseries);%handles of the GUI series
|
---|
| 12 | WaitbarPos=get(hseries.waitbar_frame,'Position');
|
---|
| 13 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
| 14 |
|
---|
| 15 | basename=fullfile(Series.RootPath,Series.RootFile) ;
|
---|
| 16 |
|
---|
| 17 | %create dir of the new images
|
---|
| 18 | [dir_images,namebase]=fileparts(basename);
|
---|
| 19 | [path,subdir_ima]=fileparts(dir_images);
|
---|
| 20 | curdir=pwd;
|
---|
| 21 | cd(path);
|
---|
| 22 | mkdir([subdir_ima '_ij']);
|
---|
| 23 | cd(curdir);
|
---|
| 24 | basename_new=fullfile(path,[subdir_ima '_ij'],namebase);
|
---|
| 25 |
|
---|
| 26 | % read imadoc
|
---|
| 27 | [XmlData,warntext]=imadoc2struct([basename '.xml']);
|
---|
| 28 | nbfield1=size(XmlData.Time,1)
|
---|
| 29 | nbfield2=size(XmlData.Time,2)
|
---|
| 30 |
|
---|
[41] | 31 | answer=msgbox_uvmat('INPUT_Y-N','apply image rescaling function levels.m')
|
---|
[40] | 32 | test_level=isequal(answer,'Yes')
|
---|
| 33 |
|
---|
| 34 | %copy the xml file
|
---|
| 35 | if exist([basename '.xml'],'file')
|
---|
| 36 | copyfile([basename '.xml'],[basename_new '.xml']);% copy the .civ file
|
---|
| 37 | t=xmltree([basename_new '.xml']);
|
---|
| 38 |
|
---|
| 39 | %update information on the first image name in the series
|
---|
| 40 | uid_Heading=find(t,'ImaDoc/Heading');
|
---|
| 41 | if isempty(uid_Heading)
|
---|
| 42 | [t,uid_Heading]=add(t,1,'element','Heading');
|
---|
| 43 | end
|
---|
| 44 | uid_ImageName=find(t,'ImaDoc/Heading/ImageName');
|
---|
| 45 | ImageName=name_generator(basename_new,num_i1(1),num_j1(1),'.png','_i_j');
|
---|
| 46 | [pth,ImageName]=fileparts(ImageName);
|
---|
| 47 | ImageName=[ImageName '.png']
|
---|
| 48 | if isempty(uid_ImageName)
|
---|
| 49 | [t,uid_ImageName]=add(t,uid_Heading,'element','ImageName');
|
---|
| 50 | end
|
---|
| 51 | uid_value=children(t,uid_ImageName);
|
---|
| 52 | if isempty(uid_value)
|
---|
| 53 | t=add(t,uid_ImageName,'chardata',ImageName)%indicate name of the first image, with ;png extension
|
---|
| 54 | else
|
---|
| 55 | t=set(t,uid_value(1),'value',ImageName)%indicate name of the first image, with ;png extension
|
---|
| 56 | end
|
---|
| 57 |
|
---|
| 58 | % %add information about image transform
|
---|
| 59 | % [t,new_uid]=add(t,1,'element','ImageTransform');
|
---|
| 60 | % [t,NameFunction_uid]=add(t,new_uid,'element','NameFunction');
|
---|
| 61 | % [t]=add(t,NameFunction_uid,'chardata','sub_background');
|
---|
| 62 | % [t,NbSlice_uid]=add(t,new_uid,'element','NbSlice');
|
---|
| 63 | % [t]=add(t,new_uid,'chardata',num2str(nbslice_i));
|
---|
| 64 | % [t,NbSlidingImages_uid]=add(t,new_uid,'element','NbSlidingImages');
|
---|
| 65 | % [t]=add(t,NbSlidingImages_uid,'chardata',num2str(nbaver));
|
---|
| 66 | % [t,LuminosityRank_uid]=add(t,new_uid,'element','RankBackground');
|
---|
| 67 | % [t]=add(t,LuminosityRank_uid,'chardata',num2str(rank));% luminosity rank almong the nbaver sliding images
|
---|
| 68 | save(t,[basename_new '.xml'])
|
---|
| 69 | end
|
---|
| 70 |
|
---|
| 71 | %main loop
|
---|
| 72 | for ifile=1:nbfield1*nbfield2
|
---|
| 73 | update_waitbar(hseries.waitbar,WaitbarPos,ifile/(nbfield1*nbfield2))
|
---|
| 74 | filename=name_generator(basename,ifile-1,1,Series.FileExt,Series.NomType);
|
---|
| 75 | num_j=mod(ifile-1,nbfield2)+1;
|
---|
| 76 | num_i=floor((ifile-1)/nbfield2)+1;
|
---|
| 77 | filename_new=name_generator(basename_new,num_i,num_j,'.png','_i_j');
|
---|
| 78 | if test_level
|
---|
| 79 | A=imread(filename);
|
---|
| 80 | C=levels(A);
|
---|
| 81 | imwrite(C,filename_new)
|
---|
| 82 | else
|
---|
| 83 | copyfile(filename,filename_new);
|
---|
| 84 | end
|
---|
| 85 | end
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | function C=levels(A)
|
---|
| 90 | %whos A;
|
---|
| 91 | B=double(A(:,:,1));
|
---|
| 92 | windowsize=round(min(size(B,1),size(B,2))/20);
|
---|
| 93 | windowsize=floor(windowsize/2)*2+1;
|
---|
| 94 | ix=[1/2-windowsize/2:-1/2+windowsize/2];%
|
---|
| 95 | %del=np/3;
|
---|
| 96 | %fct=exp(-(ix/del).^2);
|
---|
| 97 | fct2=cos(ix/(windowsize-1)/2*pi/2);
|
---|
| 98 | %Mfiltre=(ones(5,5)/5^2);
|
---|
| 99 | %Mfiltre=fct2';
|
---|
| 100 | Mfiltre=fct2'*fct2;
|
---|
| 101 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
|
---|
| 102 |
|
---|
| 103 | C=filter2(ones(windowsize)/windowsize^2,B);
|
---|
| 104 | C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
|
---|
| 105 | C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
|
---|
| 106 | C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
|
---|
| 107 | C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
|
---|
| 108 | C=tanh(B./(2*C));
|
---|
| 109 | [n,c]=hist(reshape(C,1,[]),100);
|
---|
| 110 | % figure;plot(c,n);
|
---|
| 111 |
|
---|
| 112 | [m,i]=max(n);
|
---|
| 113 | c_max=c(i);
|
---|
| 114 | [dummy,index]=sort(abs(c-c(i)));
|
---|
| 115 | n=n(index);
|
---|
| 116 | c=c(index);
|
---|
| 117 | i_select = find(cumsum(n)<0.95*sum(n));
|
---|
| 118 | if isempty(i_select)
|
---|
| 119 | i_select = 1:length(c);
|
---|
| 120 | end
|
---|
| 121 | c_select=c(i_select);
|
---|
| 122 | n_select=n(i_select);
|
---|
| 123 | cmin=min(c_select);
|
---|
| 124 | cmax=max(c_select);
|
---|
| 125 | C=(C-cmin)/(cmax-cmin)*256;
|
---|
| 126 | C=uint8(C);
|
---|