IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Millie Discussion :

[Suggestion] Ajout plugin LocalContrast


Sujet :

Millie

  1. #1
    Rédacteur
    Avatar de pseudocode
    Homme Profil pro
    Architecte système
    Inscrit en
    Décembre 2006
    Messages
    10 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Architecte système
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2006
    Messages : 10 062
    Points : 16 081
    Points
    16 081
    Par défaut [Suggestion] Ajout plugin LocalContrast
    Suite a la discussion du forum algo/traitement d'images, voici le code que j'ai utilisé pour les tests, passé au format Plugin 1.2.



    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    package millie.plugins.free;
     
    import java.awt.color.ColorSpace;
    import java.awt.image.BufferedImage;
     
    import millie.plugins.GenericPluginFilter;
    import millie.plugins.PluginInfo;
    import millie.plugins.parameters.DoubleSliderParameter;
    import millie.plugins.parameters.IntSliderParameter;
     
    /**
     * Local Contrast Filter 
     * 
     * @author xavier philippeau
     */
    @PluginInfo(name="Contraste Local", category="Réhaussement")
    public class LocalContrastPlugin extends GenericPluginFilter {
     
    	// precomputed intensity
    	private int[][] intensity;
     
    	// precomputed sum image of intensity
    	private long[][] SUM;
     
    	// saved mean intensity on neighborhood for given radius
    	private int[][] mean;
     
    	// saved contrast function for given force
    	private double[] tanh = new double[512];
     
    	// filter parameters
    	private int savedRadius=0;
    	private double savedforce=0;
     
    	public LocalContrastPlugin() {
    		setRefreshable(true);
    		setLongProcessing(false);
    		setReinitializable(true);
     
    		addParameter(new IntSliderParameter("radius", "rayon d'action",1,128,16));
    		addParameter(new DoubleSliderParameter("force", "force du contraste",1.0,20.0,1.0,8.0));
    	}
     
    	@Override
    	public BufferedImage filter() throws Exception {
    		BufferedImage input = getInputImage();
    		int width = input.getWidth();
    		int height = input.getHeight();
     
    		int radius = getParameter("radius").getIntValue();
    		double force =  getParameter("force").getDoubleValue();
     
    		// precompute intensity
    		if(this.intensity==null) {
    			this.intensity = new int[width][height];
    			for (int y=0; y<height; y++) {
    				for (int x=0; x<width; x++) {
    					int rgb = input.getRGB(x,y);
    					int r = ((rgb>>16) & 0xFF);
    					int g = ((rgb>>8 ) & 0xFF);
    					int b = ((rgb    ) & 0xFF);
    					this.intensity[x][y] = (int)(0.299f*r + 0.587f*g + 0.114f*b);
    				}
    			}
     
    			// precompute sum image
    			this.SUM = sumImage(this.intensity,width,height);
    		}
     
    		// compute mean intensity on the neighborhood
    		if (radius!=savedRadius) {
    			savedRadius=radius;
     
    			this.mean = new int[width][height];
    			for (int y=0; y<height; y++) {
    				for (int x=0; x<width; x++) {
    					int xmin = Math.max(x-radius,0);
    					int xmax = Math.min(x+radius,width-1);
    					int ymin = Math.max(y-radius,0);
    					int ymax = Math.min(y+radius,height-1);
    					double area = (xmax-xmin)*(ymax-ymin);
    					long rect = SUM[xmax][ymax] -  SUM[xmin][ymax] -  SUM[xmax][ymin] +  SUM[xmin][ymin];
    					this.mean[x][y]=(int)(rect/area);
    				}
    			}
    		}
     
    		// compute contrast function
    		if (force!=savedforce) {
    			savedforce=force;
    		    for(int i=0;i<512;i++) {
    		    	int t = i-255;
    		    	tanh[i] = 32*Math.tanh(t/255.0*force);
    		    }
    		}
     
    		// perfom local contrast on each pixel
    		BufferedImage out = new BufferedImage(width,height,ColorSpace.TYPE_RGB);
    		for(int y=0;y<height;y++) {
    			for(int x=0;x<width;x++) {
    				// intensity
    				int intensity = this.intensity[x][y];
     
    				// mean on the neighborhood
    				int mean = this.mean[x][y];
     
    				// contrast factor
    				double contrast = tanh[255+(intensity-mean)];
     
    				// original 
    				int rgb = input.getRGB(x,y);
    				int r = ((rgb>>16) & 0xFF);
    				int g = ((rgb>>8 ) & 0xFF);
    				int b = ((rgb    ) & 0xFF);
     
    				// contrasted
    				r = (int)(r + contrast);
    				g = (int)(g + contrast);
    				b = (int)(b + contrast);
     
    				// limit to 0...255
    				r = Math.max(0, Math.min(255, r));
    				g = Math.max(0, Math.min(255, g));
    				b = Math.max(0, Math.min(255, b));
     
    				out.setRGB(x, y, (r<<16)|(g<<8)|b);
    			}
    		}
     
    		return out;
    	}
     
    	// compute the sum-image of the given image
    	public long[][] sumImage(int[][] image, int width, int height) {
    		long[][] sum = new long[width][height];
    		sum[0][0] = (long)image[0][0];
    		// 2. first column
    		for (int y=1; y<height; y++)
    			sum[0][y] = (long)image[0][y] + sum[0][y-1];
    		// 3. first line
    		for (int x=1; x<width; x++)
    			sum[x][0] = (long)image[x][0] + sum[x-1][0];
    		// 4. remaining pixels
    		for (int y=1; y<height; y++)
    			for (int x=1; x<width; x++)
    				sum[x][y] = (long)image[x][y] + sum[x-1][y] + sum[x][y-1] - sum[x-1][y-1]; 
    		return sum;
    	}
     
    }
    ALGORITHME (n.m.): Méthode complexe de résolution d'un problème simple.

  2. #2
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Points : 9 818
    Points
    9 818
    Par défaut
    Ma version actuelle qui est à améliorer (il n'y a pas d'égalisation d'histogramme) :



    Sigma à 10, Contraste à 100, Rayon à 10, facteur à 70




    Partie contraste


    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
     
    	/**
             * Contraste entre -150 et 150
             * 
             * @param contrast
             * @return
             */
    	public static short[] getContrastLUT(double contrast) {
    		if(contrast>150||contrast<-150)
    			throw new IllegalArgumentException("Bad range for contrast : " + contrast);
    		short lut[] = new short[256];
    		double force = (contrast-25+150)/50;;
     
    		for(int i=0;i<256;i++) {
    			double t = (double)(i-128.0)/255.0;
    			double v = (0.5+Math.tanh(t*force)*0.5) * (255);
    			lut[i] = (short)v;
    		}
    		return lut; 
    	}
    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    public class ContrastOperator extends SimpleOperator {
     
    	private int contrast;
    	public ContrastOperator(int contrast) {
    		if(contrast>150||contrast<-150) {
    			throw new IllegalArgumentException("Bad range for contrast");
    		}
    		this.contrast = contrast;
    	}
     
    	/* (non-Javadoc)
    	 * @see millie.se.operator.SimpleOperator#compute(java.awt.image.BufferedImage, java.awt.image.BufferedImage)
    	 */
    	@Override
    	public void compute(BufferedImage output, BufferedImage input)
    			throws Exception {
     
    		LookupOperator op = new LookupOperator(PredefinedLUT.getContrastLUT(contrast));
     
    		op.compute(output, input);
    	}
    }

    Le filtre en soi :

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    /**
     * 
     */
    package filmlooking;
     
    import java.awt.image.BufferedImage;
     
    import millie.image.Kernel;
    import millie.image.PredefinedKernel;
    import millie.plugins.GenericPluginFilter;
    import millie.plugins.PluginInfo;
    import millie.plugins.parameters.IntSliderParameter;
    import millie.se.operator.ContrastOperator;
    import millie.se.operator.ConvolveOperator;
    import millie.se.operator.extender.BorderExtenderCopy;
    import millie.util.ColorUtils;
    import millie.util.MillieUtils;
     
    /**
     * @author fhu
     *
     */
    @PluginInfo(name="Contrast local", category="Cinema", description="Contraste local")
    public class LocalContrastFilter extends GenericPluginFilter {
     
     
    	public LocalContrastFilter() {
    		setPluginName("Local contrast");
    		setLongProcessing(true);
    		setRefreshable(true);
    		setWithPreview(true);
     
    		addParameter(new IntSliderParameter("contrast", "Contraste", -100, 100, 0));
    		addParameter(new IntSliderParameter("rayon", "Rayon", 1, 10, 6));
    		addParameter(new IntSliderParameter("factor", "Facteur", 1, 100, 1));
    		addParameter(new IntSliderParameter("sigma", "Sigma", 1, 20, 3));
    	}
     
     
     
    	private int range(double rgb) {
    		if(rgb>255)return 255;
    		if(rgb<0) return 0;
    		return (int) rgb;
    	}
     
    	private double gLog(double g) {
    		return Math.max(0 , 1.16*Math.pow(g, 0.333)-0.16);
    	}
    	private double carre(double g) {
    		return g*g;
    	}
     
    	@Override
    	public BufferedImage filter() throws Exception {
    		int contrast = getIntValue("contrast");
    		int rayon = getIntValue("rayon");
    		int factor = getIntValue("factor");
    		BufferedImage input = getInputImage();
     
     
    		Kernel k = PredefinedKernel.getMDIF(rayon, getIntValue("sigma"));
    		ConvolveOperator op = new ConvolveOperator(k, new BorderExtenderCopy());
     
    		BufferedImage out = op.compute(input);
    		for(int j=0; j<out.getHeight(); j++)
    			for(int i=0; i<out.getWidth();i++)  {
    				int rgbMask = out.getRGB(i, j);
     
    				int r = (rgbMask >> 16) & 0xFF ;
    				int g = (rgbMask >> 8) & 0xFF ;
    				int b = (rgbMask >> 0) & 0xFF ;
    				r*=(factor+29.0f)/30.0f;
    				g*=(factor+29.0f)/30.0f;
    				b*=(factor+29.0f)/30.0f;
    				double norme = Math.sqrt(carre(r) + carre(g) + carre(b)) / (Math.sqrt(3) * 255.0);
    				norme = gLog(norme);
    				norme*=255;
     
    				int normeI = range(norme);
    				out.setRGB(i, j, ColorUtils.getRGB(normeI, normeI, normeI));
    			}
     
    	//if(true)
    	//		return out;
     
    		BufferedImage iContrast = new ContrastOperator(contrast).compute(input);
     
    		for(int j=0; j<out.getHeight(); j++)
    			for(int i=0; i<out.getWidth();i++)  {
    				int rgbContrastedk = iContrast.getRGB(i, j);
    				int rgbMask = out.getRGB(i, j);
    				int rgb = input.getRGB(i, j);
     
     
    				float rC = (rgbContrastedk>>16)&0xFF;
    				float gC = (rgbContrastedk>>8)&0xFF;
    				float bC = (rgbContrastedk>>0)&0xFF;
    				int r = (rgb>>16)&0xFF;
    				int g = (rgb>>8)&0xFF;
    				int b = (rgb>>0)&0xFF;
     
    				int rOPI = (rgbMask>>16)&0xFF;
    				int gOPI = (rgbMask>>8)&0xFF;
    				int bOPI = (rgbMask>>0)&0xFF;
     
    				double op2 = MillieUtils.max(rOPI, gOPI, bOPI);
    				op2/=255.0;
    				if(op2>1)
    					op2=1;
     
    				r = (int) (rC * op2 + r* (1.0f-op2));
    				g = (int) (gC * op2 + g* (1.0f-op2));
    				b = (int) (bC * op2 + b* (1.0f-op2));
     
    				out.setRGB(i, j, ColorUtils.getRGB(range(r), range(g), range(b)));
    			}
     
    		return out;
    	}
     
    }
    Je ne répondrai à aucune question technique en privé

  3. #3
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Points : 9 818
    Points
    9 818
    Par défaut
    Ah zut, je croyais qu'on était dans Algo
    Je ne répondrai à aucune question technique en privé

  4. #4
    Rédacteur
    Avatar de pseudocode
    Homme Profil pro
    Architecte système
    Inscrit en
    Décembre 2006
    Messages
    10 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Architecte système
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2006
    Messages : 10 062
    Points : 16 081
    Points
    16 081
    Par défaut
    Bon, bah je garde le mien.
    ALGORITHME (n.m.): Méthode complexe de résolution d'un problème simple.

  5. #5
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Points : 9 818
    Points
    9 818
    Par défaut
    Citation Envoyé par pseudocode Voir le message
    Bon, bah je garde le mien.
    Je crois que tu as bien raison
    Je ne répondrai à aucune question technique en privé

  6. #6
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Points : 9 818
    Points
    9 818
    Par défaut
    Quoique :





    Enfin, le mien fait aussi des choses moches
    Je ne répondrai à aucune question technique en privé

  7. #7
    Rédacteur
    Avatar de pseudocode
    Homme Profil pro
    Architecte système
    Inscrit en
    Décembre 2006
    Messages
    10 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Architecte système
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2006
    Messages : 10 062
    Points : 16 081
    Points
    16 081
    Par défaut
    Oui, le problème avec le filtrage local... c'est que c'est local.

    Donc ca crée des artefacts a la limite des zones contrastées. Il faut soit diminuer la force (bof...), soit augmenter le rayon. Mais si on augmente trop le rayon, on finit par faire du filtrage global.

    Un moyen plus simple, c'est de trouver un meilleur photographe.
    ALGORITHME (n.m.): Méthode complexe de résolution d'un problème simple.

  8. #8
    Rédacteur
    Avatar de pseudocode
    Homme Profil pro
    Architecte système
    Inscrit en
    Décembre 2006
    Messages
    10 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Architecte système
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2006
    Messages : 10 062
    Points : 16 081
    Points
    16 081
    Par défaut
    Mise à jour du code pour utiliser un coef de contraste unique pour les 3 canaux R,G,B. Cela évite de saturer une composante par rapport aux autres.
    ALGORITHME (n.m.): Méthode complexe de résolution d'un problème simple.

  9. #9
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Points : 9 818
    Points
    9 818
    Par défaut
    Fait et releasé
    Je ne répondrai à aucune question technique en privé

  10. #10
    Rédacteur
    Avatar de pseudocode
    Homme Profil pro
    Architecte système
    Inscrit en
    Décembre 2006
    Messages
    10 062
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51
    Localisation : France, Hérault (Languedoc Roussillon)

    Informations professionnelles :
    Activité : Architecte système
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2006
    Messages : 10 062
    Points : 16 081
    Points
    16 081
    Par défaut
    Yes... ca déchire les plugins de la nouvelle version de l'appli.

    ALGORITHME (n.m.): Méthode complexe de résolution d'un problème simple.

  11. #11
    Rédacteur

    Avatar de millie
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    7 015
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2006
    Messages : 7 015
    Points : 9 818
    Points
    9 818
    Par défaut
    Petite optimisation :

    (utilisation d'un accès direct au pixels au lieu de passer par set/getRGB)

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    /**
     * 
     */
    package millie.plugins.core.sharpen;
     
     
    import java.awt.color.ColorSpace;
    import java.awt.image.BufferedImage;
     
    import millie.automation.Automatable;
    import millie.plugins.PluginInfo;
    import millie.plugins.appimage.GenericAppImagePlugin;
    import millie.plugins.parameters.DoubleSliderParameter;
    import millie.plugins.parameters.IntSliderParameter;
    import millie.se.image.ImageProcessor;
     
    /**
     * Local Contrast Filter 
     * 
     * @author xavier philippeau
     */
    @PluginInfo(name="Contraste Local", category="Réhaussement")
    public class LocalContrastPlugin extends GenericAppImagePlugin implements Automatable {
     
    	// precomputed intensity
    	private int[][] intensity;
     
    	// precomputed sum image of intensity
    	private long[][] SUM;
     
    	// saved mean intensity on neighborhood for given radius
    	private int[][] mean;
     
    	// saved contrast function for given force
    	private double[] tanh = new double[512];
     
    	// filter parameters
    	private int savedRadius=0;
    	private double savedforce=0;
     
    	public LocalContrastPlugin() {
    		setRefreshable(true);
    		setLongProcessing(false);
    		setReinitializable(true);
     
    		addParameter(new IntSliderParameter("radius", "rayon d'action",1,128,16));
    		addParameter(new DoubleSliderParameter("force", "force du contraste",1.0,20.0,1.0,8.0));
    	}
     
    	@Override
    	public BufferedImage filter() throws Exception {
    		BufferedImage input = getInputImage();
    		int width = input.getWidth();
    		int height = input.getHeight();
     
    		int radius = getParameter("radius").getIntValue();
    		double force =  getParameter("force").getDoubleValue();
    		int[] pixels = new ImageProcessor(input).getPixels();
     
    		// precompute intensity
    		if(this.intensity==null) {
    			this.intensity = new int[width][height];
    			for (int y=0; y<height; y++) {
    				for (int x=0; x<width; x++) {
    					int rgb = pixels[x+width*y];
    					int r = ((rgb>>16) & 0xFF);
    					int g = ((rgb>>8 ) & 0xFF);
    					int b = ((rgb    ) & 0xFF);
    					this.intensity[x][y] = (int)(0.299f*r + 0.587f*g + 0.114f*b);
    				}
    			}
     
    			// precompute sum image
    			this.SUM = sumImage(this.intensity,width,height);
    		}
     
    		// compute mean intensity on the neighborhood
    		if (radius!=savedRadius) {
    			savedRadius=radius;
     
    			this.mean = new int[width][height];
    			for (int y=0; y<height; y++) {
    				for (int x=0; x<width; x++) {
    					int xmin = Math.max(x-radius,0);
    					int xmax = Math.min(x+radius,width-1);
    					int ymin = Math.max(y-radius,0);
    					int ymax = Math.min(y+radius,height-1);
    					double area = (xmax-xmin)*(ymax-ymin);
    					long rect = SUM[xmax][ymax] -  SUM[xmin][ymax] -  SUM[xmax][ymin] +  SUM[xmin][ymin];
    					this.mean[x][y]=(int)(rect/area);
    				}
    			}
    		}
     
    		// compute contrast function
    		if (force!=savedforce) {
    			savedforce=force;
    		    for(int i=0;i<512;i++) {
    		    	int t = i-255;
    		    	tanh[i] = 32*Math.tanh(t/255.0*force);
    		    }
    		}
     
    		// perfom local contrast on each pixel
    		BufferedImage out = new BufferedImage(width,height,ColorSpace.TYPE_RGB);
    		ImageProcessor op = new ImageProcessor(out);
    		int[] opi = op.getPixels();
     
    		for(int y=0;y<height;y++) {
    			for(int x=0;x<width;x++) {
    				// intensity
    				int intensity = this.intensity[x][y];
     
    				// mean on the neighborhood
    				int mean = this.mean[x][y];
     
    				// contrast factor
    				double contrast = tanh[255+(intensity-mean)];
     
    				// original 
    				int rgb = pixels[x+width*y];
    				int r = ((rgb>>16) & 0xFF);
    				int g = ((rgb>>8 ) & 0xFF);
    				int b = ((rgb    ) & 0xFF);
     
    				// contrasted
    				r = (int)(r + contrast);
    				g = (int)(g + contrast);
    				b = (int)(b + contrast);
     
    				// limit to 0...255
    				r = Math.max(0, Math.min(255, r));
    				g = Math.max(0, Math.min(255, g));
    				b = Math.max(0, Math.min(255, b));
     
    				opi[x+width* y] = (r<<16)|(g<<8)|b;
    			}
    		}
    		op.commit();
    		return out;
    	}
     
    	// compute the sum-image of the given image
    	public long[][] sumImage(int[][] image, int width, int height) {
    		long[][] sum = new long[width][height];
    		sum[0][0] = (long)image[0][0];
    		// 2. first column
    		for (int y=1; y<height; y++)
    			sum[0][y] = (long)image[0][y] + sum[0][y-1];
    		// 3. first line
    		for (int x=1; x<width; x++)
    			sum[x][0] = (long)image[x][0] + sum[x-1][0];
    		// 4. remaining pixels
    		for (int y=1; y<height; y++)
    			for (int x=1; x<width; x++)
    				sum[x][y] = (long)image[x][y] + sum[x-1][y] + sum[x][y-1] - sum[x-1][y-1]; 
    		return sum;
    	}
     
    }
    Je ne répondrai à aucune question technique en privé

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Suggestion] Ajout Plugin WaterShed
    Par pseudocode dans le forum Millie
    Réponses: 11
    Dernier message: 15/08/2021, 09h52
  2. ajout plugin PHPExcel sous Symfony eclipse
    Par megaloplex dans le forum Plugins
    Réponses: 1
    Dernier message: 06/05/2010, 13h32
  3. [Suggestion] Ajout Plugin Lanczos Resampling
    Par pseudocode dans le forum Millie
    Réponses: 17
    Dernier message: 21/03/2009, 19h16
  4. [Suggestion] Ajout de traitement en masse
    Par millie dans le forum Millie
    Réponses: 13
    Dernier message: 28/01/2009, 17h36
  5. [Suggestion] Ajout Plugin Hough
    Par pseudocode dans le forum Millie
    Réponses: 3
    Dernier message: 12/12/2008, 19h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo