Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Java Code for converting RGB image to Ycbcr image

Java Code for converting RGB image to Ycbcr image

Scheduled Pinned Locked Moved Java
javadockerquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10533379
    wrote on last edited by
    #1

    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

    L S 2 Replies Last reply
    0
    • U User 10533379

      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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • U User 10533379

        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

        S Offline
        S Offline
        SOHAM_GANDHI
        wrote on last edited by
        #3

        I'll suggest use opencv

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups