Hello,
This is a small exercice of Multimedia class (INE5431). We need to implement:
1) Transform the image to GrayScale
2) Generate one image to each component color (R/G/B)
3) Transform the GrayScale image to binary
To transform RGB to GrayScale we need to use this expression:
Y = 0.3R + 0.59G + 0.11B;
And them, to convert the GrayScale to Binary
if (Y > 127) {b = 1; } else { b = 0; }
If we want just one color component, we need to get all image pixels and leave just the component that we want, or just copy the component to a new image.
In this project, we access an image and we have some functions to do what we want, convertion to GrayScale, Binary, and Component RGB. From the source image, we create a buffer image of the same size to all images and we create a for to go over all pixels and make the transformation and put it to the new buffer image.
GrayScale method, receive a Bufferedmage and convert it to GrayScale.
[code lang=”java”]
public static BufferedImage criaImagemCinza(BufferedImage imgJPEG) {
// Create a new buffer to BYTE_GRAY
BufferedImage img = new BufferedImage(imgJPEG.getWidth(), imgJPEG.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = img.getRaster();
WritableRaster rasterJPEG = imgJPEG.getRaster();
// Foreach pixel we transofrm it to Gray Scale and put it on the same image
for(int h=0;h<256;h++)
for(int w=0;w<256;w++) {
int[] p = new int[4];
rasterJPEG.getPixel(w, h, p);
p[0] = (int) (0.3 * p[0]);
p[1] = (int) (0.59 * p[1]);
p[2] = (int) (0.11 * p[2]);
int y = p[0] + p[1] + p[2];
raster.setSample(w,h,0,y);
}
return img;
}
[/code]
Binary Image method, receive a Bufferedmage and convert it to Binary.
[code lang="java"]
public static BufferedImage criaImagemBinaria(BufferedImage imgJPEG) {
// Create a new Binary Buffer
BufferedImage img = new BufferedImage(imgJPEG.getWidth(), imgJPEG.getHeight(), BufferedImage.TYPE_BYTE_BINARY);
WritableRaster raster = img.getRaster();
WritableRaster rasterPB = criaImagemCinza(imgJPEG).getRaster();
// Foreach pixel check if the new one must be white or black
for(int h=0;h<256;h++)
for(int w=0;w<256;w++) {
int[] p = new int[1];
rasterPB.getPixel(w, h, p);
if(p[0] > 127) {
raster.setSample(w, h, 0, 1);
} else {
raster.setSample(w, h, 0, 0);
}
}
return img;
}
[/code]
RGB Image method, receive a Bufferedmage and a Type (0 – red, 1 – green, 2 – blue) and convert it to RGB Component that is used as parameter.
[code lang=”java”]
public static BufferedImage criaImagemRGB(BufferedImage imgJPEG, int tipo) {
// Create a new RGB Buffer
BufferedImage img = new BufferedImage(imgJPEG.getWidth(), imgJPEG.getHeight(), BufferedImage.TYPE_INT_RGB);
WritableRaster rasterT = img.getRaster();
WritableRaster raster = imgJPEG.getRaster();
// Foreach pixel just use the component that is passed as parameter.
for(int h=0;h<256;h++)
for(int w=0;w<256;w++) {
int[] p = new int[4];
raster.getPixel(w,h,p);
rasterT.setSample(w,h,tipo-1,p[tipo-1]);
}
return img;
}
[/code]
Manipulate images to GrayScale, Binary and RGB Components
Matheus
Fui dentro de varios sites na internet destinado a afundar
sobre isto, li varios sites e também nem um se compara a esse até este lugar, teu Texto e exelente, bastante claramente aclimado e também explicativo, adorei.
bem-agradecido pelas informaçoes.
desculpe o portugues estou abaixo do BR a anos.
mostbet com login http://www.mostbet12033.ru
мостбет вход mostbet12034.ru
мостбет кз скачать https://mostbet12035.ru
mostbet kg регистрация http://mostbet12037.ru
скачать мост бет mostbet12036.ru
мостбеь https://www.mostbet12039.ru
mostbet kz скачать mostbet kz скачать
1уин 1уин
ван вин букмекерская контора http://www.1win5520.ru
1win программа 1win программа
прокарниз https://prokarniz36.ru .
электрокарниз купить http://prokarniz36.ru/ .
промокод melbet промокод melbet
номер мелбет http://melbet5002.ru/
мелбет горячая линия мелбет горячая линия
melbet freespins http://melbet5011.ru
melbet site alternativ https://www.melbet5012.ru
мелбет казино играть мелбет казино играть
1win жүктөп алуу http://www.1win12020.ru
филлер цена filler-kupit1.ru .
melbet бонус http://www.melbet5004.ru
Yo, Filbetcasino, is legit! Been hitting some nice wins there lately. Smooth gameplay and quick payouts. Definitely worth checking out – filbetcasino
pin up yangi bonus pin up yangi bonus
pin up to‘lov usullari pinup5012.ru
pin up promokod orqali bonus olish http://www.pinup5011.ru
pin-up http://www.pinup5013.ru
The me88app is awesome, have had it downloaded for a bit now! Super convenient for gaming on the go. Everything you need, right in your pocket man. me88app
Neue Automaten Generationen haben eingebaute Bonusspiele wie Cash
Games oder Super Games, die auch bei Free Spins mit und ohne Einzahlung aktiv werden können. Sogenannte
No Deposit Freispiele, sind in der Regel in wenigen Online Casinos vorhanden und
zusätzlich an Bedingungen geknüpft. Melde dich für unseren zweiwöchigen Newsletter an und
erhalte Zugang zu Turnieren, erfahre alles über die besten Bonusangebote, Warnungen vor unseriösen Casinos und mehr!
Dieses Willkommenspaket beginnt mit einem 120%-Bonus
bis zu €240 plus 100 Freispiele auf „Enchanted Forest Of Fortune“ von Betsoft.
Melde dich noch heute bei Trino Casino an und sichere dir 30 Freispiele ohne Einzahlung
auf Gates of Olympus 1000 mit dem Bonuscode NFSND.
Melde dich bei HunnyPlay Casino an und erhalte 150 Freispiele ohne Einzahlung
für Gates of Olympus mit dem Bonuscode BB100. Melden Sie sich noch heute im Snatch Casino an und sichern Sie sich ein 450%-Bonuspaket sowie 325 Freispiele für Ihre ersten Einzahlungen.
Manche Anbieter geben die no deposit Freispiele sogar in mehreren Etappen, sodass sich regelmäßiges Wiederkommen für Sie
lohnt. Dafür gibt es zum Beispiel 10 € Bonusguthaben ohne Einzahlung oder eine bestimmte Anzahl an Freispielen ohne Einzahlung vom
Online-Casino. Willkommensbonus bis zu 8.000 € und 500 Freispiele,
lokale Bankmethoden verfügbar, native App für iOS und Android
References:
https://online-spielhallen.de/dolly-casino-promo-code-ihr-schlussel-zu-exklusiven-vorteilen/
1вин пополнение через карту 1вин пополнение через карту
1вин ставки на спорт уз [url=www.1win5514.ru]1вин ставки на спорт уз[/url]