Ir ao conteúdo

Conversão de Imagens para GrayScale/Binária/R/G/B

Boa tarde,

Este é um pequeno exercício de Sistemas Multimidias (INE5431). O mesmo consistia em:

1) Transforme a imagem do elefante em tons de cinza.
2) Gere 3 imagens fazendo a função de split RGB, cada imagens com intensidades luminosas proporcionais a um componente de cor.
3) Implemente um programa que transforme a imagem do elefante em imagem binária.

Primeiramente, como realizar conversão de RGB para Tons de cinza:

Y = 0.3R + 0.59G + 0.11B;

Para realizar a conversão para binário precisamos uma imagem de tons binários e aplicamos a seguinte lógica:

if (Y > 127) {b = 1; } else { b = 0; }

Para deixar somente uma componente de cor, necessitamos manipular a imagem para que a mesma fique somente com a componente que desejamos.

No projeto em anexo, acessamos uma imagem e temos várias funções que realizam a conversão para GrayScale, Binária e Componente RGB. Apartir da imagem original, criamos um Buffer do mesmo tamanho e percorremos os Pixels da imagem original realizamos as transformações adequadas em cada método e jogamos nesse novo Buffer, criando assim uma nova imagem.

Método responsável por receber um BufferedImage e converter o mesmo para tons de cinza
[code lang=”java”]
public static BufferedImage criaImagemCinza(BufferedImage imgJPEG) {
// Cria um novo Buffer para BYTE GRAY
BufferedImage img = new BufferedImage(imgJPEG.getWidth(), imgJPEG.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
WritableRaster raster = img.getRaster();
WritableRaster rasterJPEG = imgJPEG.getRaster();
// Para cada Pixel realiza a transformação para tons de cinza e joga na nova imagem.
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] Método responsável por receber uma BufferedImage e converte-la para binária. [code lang="java"] public static BufferedImage criaImagemBinaria(BufferedImage imgJPEG) { // Cria um novo buffer para binário BufferedImage img = new BufferedImage(imgJPEG.getWidth(), imgJPEG.getHeight(), BufferedImage.TYPE_BYTE_BINARY); WritableRaster raster = img.getRaster(); WritableRaster rasterPB = criaImagemCinza(imgJPEG).getRaster(); // Para cada pixel realiza a verificação de se é mais cinza ou mais branco decidindo se o pixel será branco ou preto. 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]

Método responsável por receber um BufferedImage e um Tipo (R – 1, G – 2, B – 3) e só deixar a componente de cor escolhida.
[code lang=”java”]
public static BufferedImage criaImagemRGB(BufferedImage imgJPEG, int tipo) {
// Cria um novo Buffer para RGB
BufferedImage img = new BufferedImage(imgJPEG.getWidth(), imgJPEG.getHeight(), BufferedImage.TYPE_INT_RGB);

WritableRaster rasterT = img.getRaster();
WritableRaster raster = imgJPEG.getRaster();
// Para cada pixel pega a componente desejada e utiliza somente a mesma na nova imagem
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] Manipulador de imagens para GrayScale, Binária e Componente de cor desejada.

Matheus

Publicado emjava

42 Comentários

  1. x x

    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.

  2. 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

  3. 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/

  4. ECOGRA and GLI auditing provides independent verification of our gaming systems and random number generators.
    We implement SSL encryption technology across all transactions
    and data exchanges to protect player information. Company with
    legitimate Curaçao eGaming licensing, ensuring regulatory compliance and
    secure gaming operations. Game return-to-player (RTP) percentages are
    publicly displayed for all titles, ensuring transparency in expected returns.

    Our processing times range from instant deposits to withdrawals completed
    within 1-5 hours. Most deposit and withdrawal methods at LevelUp Casino are
    fee-free. LevelUp Casino offers a compelling package for
    Australian players in 2025. The quality and variety of games at LevelUp Casino
    are a direct result of its partnerships with some of the most reputable and innovative game providers in the industry.

    References:
    https://blackcoin.co/39_best-vip-online-casino-2022_rewrite_1/

  5. Whether you’re a seasoned player or a newcomer, you’ll find endless opportunities for
    fun and competition. Join us at Backgammon 247, where the
    board is always set and the community is always ready to play.
    Plus, get exclusive access to special tournaments
    where you can compete against the best players and win exciting prizes.
    Jump into a game anytime, whether you’re looking for a quick
    match or a longer session. Our user-friendly interface makes it easy for beginners
    to get started, while offering advanced features for seasoned players.
    Register for an account or play as a guest to dive into your first game in no time.

    If you are the first player to bear off all checkers,
    you will win the match and will earn a specific number of
    points. When you have navigated your way across the board,
    it’s time to bear off – which is the term used when referring to removing your checkers from the Backgammon board.

    This moves their checkers to the middle of the board,
    and they essentially have to start from the beginning.

    References:
    https://blackcoin.co/royal-reels-casino-login-a-comprehensive-guide/

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *