source: trunk/src/transform_field/ima_levels.m @ 924

Last change on this file since 924 was 924, checked in by g7moreau, 9 years ago
  • Update Copyright Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
File size: 2.2 KB
RevLine 
[810]1%=======================================================================
[924]2% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[810]3%   http://www.legi.grenoble-inp.fr
4%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
5%
6%     This file is part of the toolbox UVMAT.
7%
8%     UVMAT is free software; you can redistribute it and/or modify
9%     it under the terms of the GNU General Public License as published
10%     by the Free Software Foundation; either version 2 of the license,
11%     or (at your option) any later version.
12%
13%     UVMAT is distributed in the hope that it will be useful,
14%     but WITHOUT ANY WARRANTY; without even the implied warranty of
15%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16%     GNU General Public License (see LICENSE.txt) for more details.
17%=======================================================================
18
[574]19function DataOut=im_levels(DataIn)
20%% set GUI config: no action defined
21DataOut=[];  %default  output field
22if strcmp(DataIn,'*')
23    return
24end
25%-----------------------------------------------
26%parameters
27np=30
28%---------------------------------------------------------
29DataOut=DataIn;%default
30
31B=double(DataIn.A(:,:,1));
32windowsize=round(min(size(B,1),size(B,2))/20);
33windowsize=floor(windowsize/2)*2+1;
34ix=[1/2-windowsize/2:-1/2+windowsize/2];%
35%del=np/3;
36%fct=exp(-(ix/del).^2);
37fct2=cos(ix/((np-1)/2)*pi/2);
38%Mfiltre=(ones(5,5)/5^2);
39%Mfiltre=fct2';
40Mfiltre=fct2'*fct2;
41Mfiltre=Mfiltre/(sum(sum(Mfiltre)));
42
43C=filter2(Mfiltre,B);
44C(:,1:windowsize)=C(:,windowsize)*ones(1,windowsize);
45C(:,end-windowsize+1:end)=C(:,end-windowsize+1)*ones(1,windowsize);
46C(1:windowsize,:)=ones(windowsize,1)*C(windowsize,:);
47C(end-windowsize+1:end,:)=ones(windowsize,1)*C(end-windowsize,:);
48C=tanh(B./(2*C));
49[n,c]=hist(reshape(C,1,[]),100);
50% figure;plot(c,n);
51
52[m,i]=max(n);
53c_max=c(i);
54[dummy,index]=sort(abs(c-c(i)));
55n=n(index);
56c=c(index);
57i_select = find(cumsum(n)<0.95*sum(n));
58if isempty(i_select)
59    i_select = 1:length(c);
60end
61c_select=c(i_select);
62n_select=n(i_select);
63cmin=min(c_select);
64cmax=max(c_select);
65C=(C-cmin)/(cmax-cmin)*256;
66DataOut.AA=uint8(C);
67
68
69
70DataOut.A=uint8(C);
Note: See TracBrowser for help on using the repository browser.