Java JAVA how to get rgb values from an image

  • Thread starter Thread starter atie
  • Start date Start date
  • Tags Tags
    Image Java
AI Thread Summary
The discussion centers around creating a program to determine the ripeness of a banana using image processing and AI techniques. The user has two images of bananas—one yellow and one green—and is exploring methods to analyze these images. They have successfully loaded an image in Java and are seeking guidance on the next steps, particularly in extracting pixel data and understanding image encoding.Key points include the importance of knowing the image's color model and encoding, which can be determined using the `getType` method from the `BufferedImage` class. The user has experimented with converting the image to grayscale and binary formats but is struggling with the length of the binary string generated, which is excessively long. Suggestions include resizing the image to reduce the amount of data processed. The conversation emphasizes foundational concepts in image processing and the challenges faced by beginners in programming and AI.
atie
Messages
3
Reaction score
0
hello,

i'm kinda new in this programming thingy so i hope you guys can help me.

i wanted to code a program that can identify whether a banana is ripe or not. basically, i have two image of banana; one yellow in color and another one is green. so I'm thinking about using AI technique (backpropagation maybe) to identify the banana ripeness.

i search for some article on how to do it and most of them start with loading the image and extract the rgb value. this is what I've done. its not much because i don't know what to do next. can anybody help?

import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class banana
{
public static void main(String [] args)throws Exception
{
//get image
File imageFile= new File("yellowbanana.jpg");
BufferedImage image = ImageIO.read(imageFile);

//if file not exist
if(!(imageFile.exists())){
System.out.println("File NOT exists");
System.exit(0);}

int w = image.getWidth();
int h = image.getHeight();

System.out.println("w=" + w + ", h=" + h);

next i should get the pixel of the image. is it correct?
 
Technology news on Phys.org
atie said:
hello,

i'm kinda new in this programming thingy so i hope you guys can help me.

i wanted to code a program that can identify whether a banana is ripe or not. basically, i have two image of banana; one yellow in color and another one is green. so I'm thinking about using AI technique (backpropagation maybe) to identify the banana ripeness.

i search for some article on how to do it and most of them start with loading the image and extract the rgb value. this is what I've done. its not much because i don't know what to do next. can anybody help?

import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

public class banana
{
public static void main(String [] args)throws Exception
{
//get image
File imageFile= new File("yellowbanana.jpg");
BufferedImage image = ImageIO.read(imageFile);

//if file not exist
if(!(imageFile.exists())){
System.out.println("File NOT exists");
System.exit(0);}

int w = image.getWidth();
int h = image.getHeight();

System.out.println("w=" + w + ", h=" + h);

next i should get the pixel of the image. is it correct?

Unless the image is very small, it probably won't consist of a pixel, but will instead consist of w * h pixels. You also need to know how the image is encoded - its color model, which indicates how many bits are used for red, green, and blue, and if there are alpha bits.
 
thnk you for ur reply mark..

the banana image i have is 400pixels height and 400pixels width..

how may i know how the image is encoded? i don't understand that part.

oh, btw, i change my coding. i convert the banana image into binary. is changing the image to binary retain the color values?
 
Since you are using the BufferedImage class, you should be looking at the documentation for it (see http://docs.oracle.com/javase/1.4.2/docs/api/java/awt/image/BufferedImage.html ).

You can find out how the data is encoded by using the getType method on BufferedImage. This method returns one of the constants that describes the color encoding scheme.
 
Last edited by a moderator:
hye.. i managed to convert image into grayscale and into binary... however the binary string i got is too long (like 42 pagesssss!). how can i make it shorter? do i need to resize the picture's pixel or something?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
19
Views
2K
Replies
4
Views
5K
Replies
3
Views
1K
Replies
6
Views
3K
Replies
4
Views
2K
Replies
1
Views
1K
Back
Top