Java Code for converting RGB image to Ycbcr image
-
I tired this code for converting RGB image to Ycbcr but it doesnt work this code also contain to covert RGB to Grayscale import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.swing.*; import java.awt.image.*; import javax.imageio.ImageIO; public class Picture{ JFileChooser fileChooser = new JFileChooser(); final JFrame frame = new JFrame("Edit Image"); Container content; static BufferedImage image; BufferedImage image2; JLabel imageLabel; public Picture() { //asks for image file as input fileChooser.setDialogTitle("Choose an image file to begin:"); fileChooser.showOpenDialog(frame); File selectedFile = fileChooser.getSelectedFile(); if (fileChooser.getSelectedFile() != null) { try { //reads File as image image = ImageIO.read(selectedFile); } catch (IOException e) { System.out.println("Invalid image file: " + selectedFile); System.exit(0); } } else { System.out.println("No File Selected!"); } } public int width() { //returns width of present image int width = image.getWidth(); return width; } public int height() { //returns height of present image int height = image.getHeight(); return height; } /* public void getImage() { this.image = image2; } */ public void saveImage() { //saves current image as JPEG fileChooser.setDialogTitle("Save this image?"); fileChooser.showSaveDialog(frame); try { //writes new file ImageIO.write(this.image, "JPG", fileChooser.getSelectedFile()); } catch (IOException f) { System.out.println("Saving failed! Could not save image."); } } public void show() { //set frame title, set it visible, etc content = frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); //add the image to the frame ImageIcon icon = new ImageIcon(image); imageLabel = new JLabel(icon); frame.setContentPane(imageLabel); //add a menubar on the frame with a single option: saving the image JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu
-
I tired this code for converting RGB image to Ycbcr but it doesnt work this code also contain to covert RGB to Grayscale import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.swing.*; import java.awt.image.*; import javax.imageio.ImageIO; public class Picture{ JFileChooser fileChooser = new JFileChooser(); final JFrame frame = new JFrame("Edit Image"); Container content; static BufferedImage image; BufferedImage image2; JLabel imageLabel; public Picture() { //asks for image file as input fileChooser.setDialogTitle("Choose an image file to begin:"); fileChooser.showOpenDialog(frame); File selectedFile = fileChooser.getSelectedFile(); if (fileChooser.getSelectedFile() != null) { try { //reads File as image image = ImageIO.read(selectedFile); } catch (IOException e) { System.out.println("Invalid image file: " + selectedFile); System.exit(0); } } else { System.out.println("No File Selected!"); } } public int width() { //returns width of present image int width = image.getWidth(); return width; } public int height() { //returns height of present image int height = image.getHeight(); return height; } /* public void getImage() { this.image = image2; } */ public void saveImage() { //saves current image as JPEG fileChooser.setDialogTitle("Save this image?"); fileChooser.showSaveDialog(frame); try { //writes new file ImageIO.write(this.image, "JPG", fileChooser.getSelectedFile()); } catch (IOException f) { System.out.println("Saving failed! Could not save image."); } } public void show() { //set frame title, set it visible, etc content = frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); //add the image to the frame ImageIcon icon = new ImageIcon(image); imageLabel = new JLabel(icon); frame.setContentPane(imageLabel); //add a menubar on the frame with a single option: saving the image JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu
This is the third time you have posted this question; please post only once. Also it is very difficult to read unformatted code blocks. Please edit your question, indent your code properly and add <pre> tags around it so it looks like:
try {
if (grabber.grabPixels() != true) {
try {
throw new AWTException("Grabber returned false: " + grabber.getStatus());
} catch (final Exception e) {};Note that your null
catch
clause in the above is not good practice as it means you will ignore all the errors that get thrown. Also you need to do some diagnosis of your own on this and explain to us what results you expect, what results you actually get, and where in the code the problems occur.Veni, vidi, abiit domum
-
I tired this code for converting RGB image to Ycbcr but it doesnt work this code also contain to covert RGB to Grayscale import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; import javax.swing.*; import java.awt.image.*; import javax.imageio.ImageIO; public class Picture{ JFileChooser fileChooser = new JFileChooser(); final JFrame frame = new JFrame("Edit Image"); Container content; static BufferedImage image; BufferedImage image2; JLabel imageLabel; public Picture() { //asks for image file as input fileChooser.setDialogTitle("Choose an image file to begin:"); fileChooser.showOpenDialog(frame); File selectedFile = fileChooser.getSelectedFile(); if (fileChooser.getSelectedFile() != null) { try { //reads File as image image = ImageIO.read(selectedFile); } catch (IOException e) { System.out.println("Invalid image file: " + selectedFile); System.exit(0); } } else { System.out.println("No File Selected!"); } } public int width() { //returns width of present image int width = image.getWidth(); return width; } public int height() { //returns height of present image int height = image.getHeight(); return height; } /* public void getImage() { this.image = image2; } */ public void saveImage() { //saves current image as JPEG fileChooser.setDialogTitle("Save this image?"); fileChooser.showSaveDialog(frame); try { //writes new file ImageIO.write(this.image, "JPG", fileChooser.getSelectedFile()); } catch (IOException f) { System.out.println("Saving failed! Could not save image."); } } public void show() { //set frame title, set it visible, etc content = frame.getContentPane(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); //add the image to the frame ImageIcon icon = new ImageIcon(image); imageLabel = new JLabel(icon); frame.setContentPane(imageLabel); //add a menubar on the frame with a single option: saving the image JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu
I'll suggest use opencv