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] Mise à jour Plugin Bloom


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] Mise à jour Plugin Bloom
    J'ai modifié le plugin Bloom pour mieux gérer les image RGB



    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
    /**
     * 
     */
    package millie.plugins.core.artistic;
     
    import java.awt.image.BufferedImage;
     
    import millie.image.PredefinedKernel;
    import millie.plugins.GenericPluginFilter;
    import millie.plugins.parameters.ComboBoxParameter;
    import millie.plugins.parameters.IntSliderParameter;
    import millie.se.operator.ConvolveOperator;
    import millie.se.operator.extender.BorderExtenderCopy;
     
    /**
     * @author Xavier Philippeau
     *
     */
    public class BloomEffectPlugin extends GenericPluginFilter {
    	public BloomEffectPlugin() {
    		setPluginName("Effet Blooming RGB");
    		setLongProcessing(true);
    		//setRefreshable(true);
    		ComboBoxParameter visu = new ComboBoxParameter("visu", "Type de visualisation");
    		visu.addItem("normal", "Normal");
    		visu.addItem("mask", "Masque");
    		visu.addItem("blurmask", "Masque flouté");
     
    		addParameter(visu);
    		addParameter(new IntSliderParameter("threshold", "Seuil",      1,100,50));
    		addParameter(new IntSliderParameter("radius",    "Rayon",      1,20,8));
    		addParameter(new IntSliderParameter("overlay",   "Visibilité", 1,100,25));
    	}
     
    	@Override
    	public BufferedImage filter() throws Exception {
    		BufferedImage input = getInputImage();
    		int radius = getIntValue("radius");
    		double threshold = getIntValue("threshold")*0.01;
    		double overlay = getIntValue("overlay")*0.01;
     
    		// on cherche le max de luminosité
    		int graymax = 0;
    		for (int y = 0; y < input.getHeight(); y++) {
    			for (int x = 0; x < input.getWidth(); x++) {
    				int rgb = input.getRGB(x, y);
    				int gray = rgb2gray(rgb);
    				if (gray>graymax) graymax=gray;
    			}
    		}
    		int graythr = (int)(graymax*threshold); 
     
    		// on calcule le masque
    		BufferedImage mask = new BufferedImage(input.getWidth(), input.getHeight(), input.getType()); 
    		for (int y = 0; y < input.getHeight(); y++) {
    			for (int x = 0; x < input.getWidth(); x++) {
    				int rgb = input.getRGB(x, y);
    				int gray = rgb2gray(rgb);
    				if (gray<=graythr) continue;
    				double ratio = ((double)(gray-graythr))/(graymax-graythr);
    				rgb = multiply(rgb,ratio);
    				mask.setRGB(x, y, rgb);
    			}
    		}
     
    		if(getStringValue("visu").equals("mask"))
    			return mask;
     
    		// on applique un flou gaussien
    		ConvolveOperator op = new ConvolveOperator(PredefinedKernel.getGaussianKernel(radius, radius*0.5), new BorderExtenderCopy());
    		double e0=energy(mask);
    		mask = op.compute(mask);
    		double e1=energy(mask);
     
    		// boost l'energie du masque flouté
    		double ratio = (e1==0)?0:e0/e1;
    		multiply(mask, ratio);
     
    		if(getStringValue("visu").equals("blurmask"))
    			return mask;
     
    		// overlay image + masque flouté
    		BufferedImage out = new BufferedImage(input.getWidth(), input.getHeight(), input.getType());
    		for (int y = 0; y < out.getHeight(); y++) {
    			for (int x = 0; x < out.getWidth(); x++) {
    				int rgbInput = input.getRGB(x, y);
    				int r = (rgbInput>>16)&0xFF;
    				int g = (rgbInput>>8)&0xFF;
    				int b = (rgbInput)&0xFF;
     
    				int rgbmask = mask.getRGB(x,y);
    				int rm = (rgbmask>>16)&0xFF;
    				int gm = (rgbmask>>8)&0xFF;
    				int bm = (rgbmask)&0xFF;
     
    				r = (int) Math.min(255, r + 2*overlay*rm );
    				g = (int) Math.min(255, g + 2*overlay*gm );
    				b = (int) Math.min(255, b + 2*overlay*bm );
     
    				out.setRGB(x,y, 0xFF000000+(r<<16)+(g<<8)+b);
    			}
    		}
     
    		return out;
    	}
     
    	// conversion rgb en niveau de gris (luminosité)
    	private int rgb2gray(int rgb) {
    		int r = (rgb >> 16) & 0xFF;
    		int g = (rgb >> 8) & 0xFF;
    		int b = rgb & 0xFF;
    		int l = (int)(0.299*r + 0.587*g + 0.114*b);
    		return l;	
    	}
     
    	// calcul de l'energie d'une image
    	private double energy(BufferedImage c) {
    		int width = c.getWidth();
    		int height = c.getHeight();
    		double e=0;
    		for (int y=0; y<height; y++) {
    			for (int x=0; x<width; x++)	{
    				int rgb=c.getRGB(x, y)&0xFF;
    				int v = rgb2gray(rgb);
    				e+=v*v;
    			}
    		}
    		return Math.sqrt(e);
    	}
     
    	// multiplication rgb par un facteur
    	private int multiply(int rgb , double factor) {
    		int r = (rgb >> 16) & 0xFF;
    		int g = (rgb >> 8) & 0xFF;
    		int b = rgb & 0xFF;
    		r = (int)Math.min(255,r*factor);
    		g = (int)Math.min(255,g*factor);
    		b = (int)Math.min(255,b*factor);
    		return 0xFF000000 + (r<<16) + (g<<8) + b;
    	}
     
    	// multiplication image par un facteur
    	private void multiply(BufferedImage c , double factor) {
    		int width = c.getWidth();
    		int height = c.getHeight();
    		for (int y=0; y<height; y++) {
    			for (int x=0; x<width; x++) {
    				int rgb = c.getRGB(x, y);
    				rgb = multiply(rgb,factor);
    				c.setRGB(x, y, rgb);
    			}
    		}
    	}
     
    }
    ALGORITHME (n.m.): Méthode complexe de résolution d'un problème simple.

  2. #2
    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
    On commence a faire des choses sympa avec cette appli.

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

  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
    Juste si t'avais pas vu, il y a dans le menu Fichier, ya truc Dupliquer pour dupliquer l'image (style pour voir avant et après).

    Je l'ajouterais
    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
    Citation Envoyé par millie Voir le message
    Juste si t'avais pas vu, il y a dans le menu Fichier, ya truc Dupliquer pour dupliquer l'image (style pour voir avant et après).
    Oui, je sais. Je l'utilise tout le temps. Pourquoi tu me dis ca ?
    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
    Oui, je sais. Je l'utilise tout le temps. Pourquoi tu me dis ca ?
    Comme j'avais vu que t'avais fait un screen avec plusieurs images d'ouvert avec différent paramètre, me suis demandé un coup si t'avais vu le truc Dupliquer ou si tu faisais des copiers/nouveau/coller ^^
    Je ne répondrai à aucune question technique en privé

  6. #6
    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
    Citation Envoyé par millie Voir le message
    Comme j'avais vu que t'avais fait un screen avec plusieurs images d'ouvert avec différent paramètre, me suis demandé un coup si t'avais vu le truc Dupliquer ou si tu faisais des copiers/nouveau/coller ^^
    Non, j'utilise toute les fonctionnalités du logiciel.

    Les 4 images dupliquées sont, de gauche a droite:

    1: image originale
    2: image 1 + filtre bilateral
    3: image 2 + filtre bloom
    4: image 3 + teinte/saturation

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

  7. #7
    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
    J'ai integré dans la version en cours
    Je ne répondrai à aucune question technique en privé

  8. #8
    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
    version releasée
    Je ne répondrai à aucune question technique en privé

  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
    J'ai fait le même type d'optimisation + utilisation du FastGaussianBlur

    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
    /**
     * 
     */
    package millie.plugins.core.artistic;
     
    import java.awt.image.BufferedImage;
     
    import millie.automation.Automatable;
    import millie.plugins.PluginInfo;
    import millie.plugins.appimage.GenericAppImagePlugin;
    import millie.plugins.parameters.ComboBoxParameter;
    import millie.plugins.parameters.IntSliderParameter;
    import millie.se.image.ImageProcessor;
    import millie.se.operator.FastGaussianBlurOperator;
     
    /**
     * @author Xavier Philippeau
     *
     */
    @PluginInfo(name="Effet Blooming", category="Artistique", description="Effet Blooming")
    public class BloomingEffectPlugin extends GenericAppImagePlugin implements Automatable {
    	public BloomingEffectPlugin() {
    		setPluginName("Effet Blooming RGB");
    		setLongProcessing(true);
    		//setRefreshable(true);
    		ComboBoxParameter visu = new ComboBoxParameter("visu", "Type de visualisation");
    		visu.addItem("normal", "Normal");
    		visu.addItem("mask", "Masque");
    		visu.addItem("blurmask", "Masque flouté");
     
    		addParameter(visu);
    		addParameter(new IntSliderParameter("threshold", "Seuil",      1,100,50));
    		addParameter(new IntSliderParameter("radius",    "Rayon",      1,20,8));
    		addParameter(new IntSliderParameter("overlay",   "Visibilité", 1,100,25));
    	}
     
    	@Override
    	public BufferedImage filter() throws Exception {
    		BufferedImage input = getInputImage();
    		int radius = getIntValue("radius");
    		double threshold = getIntValue("threshold")*0.01;
    		double overlay = getIntValue("overlay")*0.01;
    		int width = input.getWidth();
    		int[] pixels = new ImageProcessor(input).getPixels();
     
    		// on cherche le max de luminosité
    		int graymax = 0;
    		for (int y = 0; y < input.getHeight(); y++) {
    			for (int x = 0; x < input.getWidth(); x++) {
    				int rgb = pixels[x+width*y];
    				int gray = rgb2gray(rgb);
    				if (gray>graymax) graymax=gray;
    			}
    		}
    		int graythr = (int)(graymax*threshold); 
     
    		// on calcule le masque
    		BufferedImage mask = new BufferedImage(input.getWidth(), input.getHeight(), input.getType()); 
    		ImageProcessor maskP = new ImageProcessor(mask);
    		int[] maskPixels = maskP.getPixels();
     
    		for (int y = 0; y < input.getHeight(); y++) {
    			for (int x = 0; x < input.getWidth(); x++) {
    				int rgb = input.getRGB(x, y);
    				int gray = rgb2gray(rgb);
    				if (gray<=graythr) continue;
    				double ratio = ((double)(gray-graythr))/(graymax-graythr);
    				rgb = multiply(rgb,ratio);
    				maskPixels[x+y*width] = rgb;
    			}
    		}
     
    		if(getStringValue("visu").equals("mask"))
    			return mask;
     
    		// on applique un flou gaussien
    		FastGaussianBlurOperator op = new FastGaussianBlurOperator(radius);
    		double e0=energy(maskPixels, mask.getWidth(), mask.getHeight());
    		maskP.commit();
    		mask = op.compute(mask);
    		maskP = new ImageProcessor(mask);
    		maskPixels = maskP.getPixels();
    		double e1=energy(maskPixels, mask.getWidth(), mask.getHeight());
     
    		// boost l'energie du masque flouté
    		double ratio = (e1==0)?0:e0/e1;
    		multiply(maskPixels, ratio);
     
    		if(getStringValue("visu").equals("blurmask")) {
    			maskP.commit();
    			return mask;
    		}
     
    		// overlay image + masque flouté
    		BufferedImage out = new BufferedImage(input.getWidth(), input.getHeight(), input.getType());
    		ImageProcessor oProc = new ImageProcessor(out);
    		int[] opi = oProc.getPixels();
    		for(int i = 0;i<opi.length;i++) {
    			int rgbInput = pixels[i];
    			int r = (rgbInput>>16)&0xFF;
    			int g = (rgbInput>>8)&0xFF;
    			int b = (rgbInput)&0xFF;
     
    			int rgbmask = maskPixels[i];
    			int rm = (rgbmask>>16)&0xFF;
    			int gm = (rgbmask>>8)&0xFF;
    			int bm = (rgbmask)&0xFF;
     
    			r = (int) Math.min(255, r + 2*overlay*rm );
    			g = (int) Math.min(255, g + 2*overlay*gm );
    			b = (int) Math.min(255, b + 2*overlay*bm );
     
    			opi[i] = 0xFF000000+(r<<16)+(g<<8)+b;
    		}
    		oProc.commit();
    		return out;
    	}
     
    	// conversion rgb en niveau de gris (luminosité)
    	private int rgb2gray(int rgb) {
    		int r = (rgb >> 16) & 0xFF;
    		int g = (rgb >> 8) & 0xFF;
    		int b = rgb & 0xFF;
    		int l = (int)(0.299*r + 0.587*g + 0.114*b);
    		return l;	
    	}
     
    	// calcul de l'energie d'une image
    	private double energy(int[] pixels, int width, int height) {
    		double e=0;
    		for (int y=0; y<height; y++) {
    			for (int x=0; x<width; x++)	{
    				int rgb=pixels[x+width*y]&0xFF;
    				int v = rgb2gray(rgb);
    				e+=v*v;
    			}
    		}
    		return Math.sqrt(e);
    	}
     
    	// multiplication rgb par un facteur
    	private int multiply(int rgb , double factor) {
    		int r = (rgb >> 16) & 0xFF;
    		int g = (rgb >> 8) & 0xFF;
    		int b = rgb & 0xFF;
    		r = (int)Math.min(255,r*factor);
    		g = (int)Math.min(255,g*factor);
    		b = (int)Math.min(255,b*factor);
    		return 0xFF000000 + (r<<16) + (g<<8) + b;
    	}
     
    	// multiplication image par un facteur
    	private void multiply(int[] pixels, double factor) {
    		for(int i=0;i<pixels.length;i++)
    			pixels[i] = multiply(pixels[i], factor);
    	}
     
    }
    Je ne répondrai à aucune question technique en privé

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

Discussions similaires

  1. Réponses: 2
    Dernier message: 26/02/2011, 16h18
  2. [Suggestion] Mise à jour Operator Skeleton
    Par pseudocode dans le forum Millie
    Réponses: 1
    Dernier message: 01/11/2009, 17h40
  3. [Suggestion] Mise à jour Operator Canny
    Par pseudocode dans le forum Millie
    Réponses: 1
    Dernier message: 01/11/2009, 17h39

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