Results 1 to 4 of 4
  1. #1
    tranceslave is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default Really tough question

    I have to complete the ImageManipulation Class that allows the manipulation of an image via two static methods in Java.

    The first method will rotate the given area by 90 degrees in clockwise direction

    /**
    * Rotate the pixels in the given area by 90 degrees in
    * clockwise direction.
    * In case the centre of the area is to close the border of
    * the picture no rotation willing occur.
    *
    * @param image the image you are performing the rotation on
    * @param x x-coordinate of the centre of the rectangle
    * @param y y-coordinate of the centre of the rectangle
    * @param size half the length/width of the square
    * @return
    */
    static public void rotate(BufferedImage image,
    int x, int y,int size) {

    //Add some code

    }
    The second method will for the given area calculate for each a value according to a 3 X 3 matrix.Depending on this value the pixel stays the same or gets altered. This is a basic method to detect edges in a picture.


    /**
    * PERFORM a threshold calculation for each pixel of specified square and dependent on outcome
    * alters a pixel or not. <p>
    *
    * Apart from pixel on the edge of the image each pixel is surrounded by 8 other pixels.
    * A 3 x 3 matrix is given as a parameter to calculate for each pixel out of its on rgb
    * value and that of the its 8 surrounding pixel a value.
    * The calculation is done in the following way.
    * For each of the nine pixels a value is calculated by adding its red, green and blue
    * component together.
    * These values are multiplied by the corresponding value in the matrix. The center pixel
    * correspond to the cell 1,1 in the matrix, the pixel top right of the center pixel correspond
    * to the cell 2,0 and so on.
    *
    * All these values are added up. If the absolute value of this sum is less than 250 the pixel
    * will be unchanged. Otherwise the new value for a pixel (r,g,b) will be (255-r,255-g,255-b).
    *
    * All the calculation for the threshold should be done on the original values, but some
    * might get altered. Hence the first two lines of this method are given. Here a copy of the
    * BufferedImage is created. You should alter the image and use temp for the calculation.
    *
    *
    * @param image BufferedImage object representing the
    * image you are performing the swap on
    * @param matrix a 3x3 matrix with the coefficients for the 9 pixels.
    * @param x x-coordinate of the centre of the rectangle
    * @param y y-coordinate of the centre of the rectangle
    * @param size half the length/width of the square
    *
    */
    static public void toCanny(BufferedImage image,
    double[][] matrix,
    int x, int y, int size) {
    BufferedImage temp=new BufferedImage(image.getWidth(), image.getHeight(), image.getType());
    (temp.getGraphics()).drawImage(image,0,0,image.get Width(), image.getHeight(),null );


    // add more code here




    }

    Any kind of help will be appreciated!

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Why don't you give it a go with your best attempt here first, and then post your attempt. You will learn much more if we do it this way. Oh, and a hearty welcome to this forum!

  3. #3
    tranceslave is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default

    hello again i attempted some code..

    Java Code:
    static public void rotate(BufferedImage image,
    			    int x, int y,int size) {
        	
        	int xaxes=0;
        	int yaxes=0; 
        	int halfpic1=0;
        	int halfpic2=0;
    
        	//Checks if it inside the bounds if not then it doesn't rotate the square
        	if((x-size)>0 && (y-size)>0){
        	    if(x+size<image.getWidth() && y+size<image.getHeight()){
        		//If is inside the bounds it starts the nested loop and checks every pixel
        		int maxi = Math.min(image.getWidth(),x+size);
        		int maxj = Math.min(image.getHeight(),y+size);
        		for (int i = Math.max(0,x-size); i<maxi; i++) {
        		    //Here is a difference in the loop(j<y) so it doesn't go again through the pixels and rotate half of the image back
        		    for (int j = Math.max(0,y-size); j<y; j++) {
        			//Make the rotation of the square
        			xaxes=(2*x-i);
        			yaxes=(2*y-j-1);//So it connects exactly the 2 pictures
        			//Setting the rotated images in the correct place 
        			halfpic1= image.getRGB(i,j);
        			halfpic2= image.getRGB(xaxes, yaxes);	       	
        			image.setRGB(xaxes,yaxes,halfpic1);
        			image.setRGB(i,j,halfpic2);
        		    }//end of x loop
        		}//end of y loop
        		
        	    }//end of first if statement
        	}//end of second if statement
    
        	
            }
    the above code rotates a part of the image by 180 degrees by cutting the part into two subimages.. but we are told to do it by 4 subimages

  4. #4
    tranceslave is offline Member
    Join Date
    Feb 2010
    Posts
    3
    Rep Power
    0

    Default



    the result should be like that.. that part of the picture is rotated by 90 degrees.The mouse pointer is on that part. If the mouse pointer is at the border of the picture,that part of the picture is not rotated

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Really Really Tough Bug in JSP
    By ajt111 in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 10-28-2009, 05:49 PM
  3. ur help on my question
    By jameela in forum New To Java
    Replies: 4
    Last Post: 10-13-2008, 12:38 PM
  4. Tough Homework Questions, PLEASE HELP!
    By passage in forum New To Java
    Replies: 21
    Last Post: 01-16-2008, 11:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •