Tips for implementing MonochromImage class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dodo1267
    New Member
    • Dec 2006
    • 7

    Tips for implementing MonochromImage class

    i need tips for implimintiing this class:
    http://www.cs.huji.ac. il/~intro2cs/doc/ex4/doc/index.html
    thanks
  • dodo1267
    New Member
    • Dec 2006
    • 7

    #2
    i mean for the last methods

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      Originally posted by dodo1267
      i mean for the last methods
      Be more specific. What exactly do you need help with?

      Comment

      • dodo1267
        New Member
        • Dec 2006
        • 7

        #4
        Originally posted by r035198x
        Be more specific. What exactly do you need help with?
        i need help in the animate,rotate and blur methods please!!
        i am waiting for ideas!!
        thanks .

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by dodo1267
          i need help in the animate,rotate and blur methods please!!
          i am waiting for ideas!!
          thanks .
          Have you written code that is using these methods? You are still not being clear.

          Comment

          • dodo1267
            New Member
            • Dec 2006
            • 7

            #6
            Originally posted by r035198x
            Have you written code that is using these methods? You are still not being clear.
            no my job first is to compile this class without error then use a tester to check the class i mean the driver will just use this class checking if it working right.
            at fisrt we construct an image(matrix) and filling it with certain luminosity according to the constructor and then do all the other methods on our image.
            i mean i need the function("trick ") in doing this methods mentioned abbove.
            we mainly use arrys and loops with rows and columns to introrduce the image.

            Comment

            • r035198x
              MVP
              • Sep 2006
              • 13225

              #7
              Originally posted by dodo1267
              no my job first is to compile this class without error then use a tester to check the class i mean the driver will just use this class checking if it working right.
              at fisrt we construct an image(matrix) and filling it with certain luminosity according to the constructor and then do all the other methods on our image.
              i mean i need the function("trick ") in doing this methods mentioned abbove.
              we mainly use arrys and loops with rows and columns to introrduce the image.
              To compile the class you need the source code for that class. Do you have it?

              Comment

              • dodo1267
                New Member
                • Dec 2006
                • 7

                #8
                Originally posted by r035198x
                To compile the class you need the source code for that class. Do you have it?
                that what i am asking for i need help in writing the source code of these methods mentioned above!!

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by dodo1267
                  that what i am asking for i need help in writing the source code of these methods mentioned above!!
                  Interesting. Now where are you so far with it?

                  Comment

                  • dodo1267
                    New Member
                    • Dec 2006
                    • 7

                    #10
                    Originally posted by r035198x
                    Interesting. Now where are you so far with it?
                    i am still writing the other methods :

                    Code:
                     ################## 
                    import intro2cs.utils.*;
                    ####################
                     
                    import intro2cs.Ex4.IntroError;
                     
                     
                    public class MonochromImage {
                     
                    private int _width;
                    private int _height;
                    private int[][] _image;
                    private int luminosity;
                    public static int datapix;
                    public static int value;
                    public static int temppix; 
                    public static final int ERROR_BAD_PARM= 2;
                    public static final int ERROR_GENERAL= 1;
                    public static final int ERROR_PARAM_BOUND= 3;
                    public static final int ERROR_UNKNOWN= 0;
                    public static final int BG_DEFAULT = 255;
                    * Represents a clock-wise rotation of 90 degrees
                    *************************************************************************/
                    public static final int ROTATE_90CW = 1;
                    /*************************************************************************
                    * Represents a 180 degree rotation
                     
                    public static final int ROTATE_180 = 2;
                    public MonochromImage(int height, int width, int luminosity) {
                     
                    if(width>=0) _width=width;
                    else 
                    IntroError(ERROR_BAD_PARAM,"width is not positive");
                    if(height>=0) _height=height;
                    else
                    IntroError(ERROR_BAD_PARAM,"height is not positive");
                    if(luminosity>=0&&luminosity<=255) _luminosity=luminosity;
                    else
                    IntroError(ERROR_PARAM_BOUND,"luminosity is out of bound");
                    for(int i=0;i<_heigth;i++){
                    for(j=0;j<_width;j++)
                    {
                    _image[i][j]=liminosity;
                    }
                    }
                     
                     
                    }
                     
                    public MonochromImage(int height, int width){
                     
                    if(width>=0) _width=width;
                    else row
                    IntroError(ERROR_BAD_PARAM,"width is not positive");
                    if(height>=0) _height=height;
                    else
                    IntroError(ERROR_BAD_PARAM,"height is not positive");
                     
                    _luminosity=BG_DEFAULT;
                    for(int i=1,i<height;i++){
                    for(int j=1;j<width;j++)
                    {
                    _image[i][j]=_luminosity;
                    }
                     
                    }
                    }
                     
                    /*************************************************************************
                    *************************************************************************/
                    public MonochromImage(MonochromImage source) {
                     
                    if(source==NULL) IntroError(ERROR_GENERAL,"source is empty");
                    this(source.getWidth,source.getHieght);
                     
                     
                     
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage(int[][] data){
                     
                    image = new int[][];
                    	_image=image.setData(data);
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public int getHeight(){
                    return _height;
                     
                     
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public int getWidth()
                    return _width;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public int getValue(int row, int column){
                    if(row>_height-1||row<0)
                    IntroError(ERROR_PARM_BOUND,"the row index is out of bound");
                    if(column>_width-1||column<0)
                    IntroError(ERROR_PARAM_BOUND,"the column index is out of bound")
                    datapix=_image[row-1][column-1]; 
                    return datapix;
                    }
                     
                    /************************************************************************
                     
                    public int setValue(int row,int column, int luminosity){
                    if(((row<0)||(row>_height-1))||((column<0)||(column>_width-1)))
                    IntroError(ERROR_PARAM_BOUND);
                    if((luminosity<0)||(luminosity>255) IntroError(ERROR_PARAM_BOUND));
                    _image[row][column]=luminosity;
                    value=_image[row][column];
                    return value;
                     
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public int[][] getData(){
                    for(int i=0;i<data[i].length();i++){
                     
                    newimage = new int[_height][_width];
                    for(int i=0;i<_height;i++) {
                    for(int j=0;j<_width;j++)
                    newimage[i][j]=_image[i][j]; 
                    }
                    	return newimage;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage setData(int[][] data){
                    if(data==null) Intro2Error(GENERAL_ERROR,"data is null");
                     
                     
                     
                    for(int i=0;i<data[i].length();i++){
                     
                    tempmax=i;
                    if(tempmax>max)
                    max=tempmax;
                    }
                     
                    _width=max;
                     
                     
                    _image = new int[_height][_width];
                     
                    for(i=0;i<_height;i++) {
                    for(j=0;j<_width;j++)
                    _image[i][j]=BG_DEFAULT;
                    }
                     
                    for(int i=0;i<data.length;i++){
                    for(int j=0;j<data[j].length;j++)
                    {
                    if(data[i]][j]==null) IntroError(ERROR_PARAM_BOUND);
                    else
                    if(data[i][j]<0) _image[i][j]=0;
                    else
                    if(data[i][j]>255) _image[i][j]=255;
                    else
                    _image[i][j]=data[i][j];
                    }
                     
                     
                     
                    } 
                     
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage blur(int radius){
                     
                    	return this;
                     
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage rotate(int rotation){
                     
                    return this; 
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage flipVertical(){
                     
                    for(i=0;i<_height;i++){
                    for(j=0;j<_width/2;j++){
                    temppix=_image[i][j];
                    _image[i][j]=image[i][_width-i-1];
                    _image[i][j]=temppix;
                    }
                    }
                    	return this;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage flipHorizontal(){
                     
                    for(i=0;i<_height/2;i++) {
                    for(j=0;j<_width;j++)
                    temppix=_image[i][j];
                    _image[i][j]=_image[_height-j-1][i];
                    _image[i][j]=temppix;
                    return this;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage imprint(MonochromImage source, int row, int column){
                     
                     
                    if(source==null) return source;
                    else
                    if((row>_height)&&(column>_width)) return source;
                     
                     
                     
                     
                     
                     
                    return this;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage imprint(MonochromImage source){
                     
                    return this;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage add(MonochromImage source, int row, int column){
                     
                    return this;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage add(MonochromImage source){
                     
                    return this;
                    }
                     
                    /*************************************************************************
                     
                    *************************************************************************/
                    public MonochromImage add(int luminosity){
                     
                    	return this;
                    }
                     
                    for(int i=1;i<data[i].length();i++){
                     
                    tempmax=i;
                    if(tempmax>max)
                    max=tempmax;
                    }
                     
                    _width=max;
                    _image = new int[_height][_width];
                    for(int i=0;i<data.length;i++){
                    for(int j=0;j<data[j].length;j++)
                    {
                    if(data[i][j]<0) _image[i][j]=0;
                    else
                    if(data[i][j]>255) _image[i][j]=255;
                    else
                    _image[i][j]=data[i][j];
                     
                    for(int i=0;i<_image.length;i++){ 
                    for(j=data[j].length+1;j<_image[_width].length;j++)
                    {
                    _image[i][j]=BG_DEFAULT;
                    }
                    }
                     
                    /*************************************************************************
                    Last edited by r035198x; Dec 12 '06, 03:54 PM. Reason: code tags

                    Comment

                    • r035198x
                      MVP
                      • Sep 2006
                      • 13225

                      #11
                      Originally posted by dodo1267
                      i am still writing the other methods :

                      Code:
                       ################## 
                      import intro2cs.utils.*;
                      ####################
                       
                      import intro2cs.Ex4.IntroError;
                       
                       
                      public class MonochromImage {
                       
                      private int _width;
                      private int _height;
                      private int[][] _image;
                      private int luminosity;
                      public static int datapix;
                      public static int value;
                      public static int temppix; 
                      public static final int ERROR_BAD_PARM= 2;
                      public static final int ERROR_GENERAL= 1;
                      public static final int ERROR_PARAM_BOUND= 3;
                      public static final int ERROR_UNKNOWN= 0;
                      public static final int BG_DEFAULT = 255;
                      * Represents a clock-wise rotation of 90 degrees
                      *************************************************************************/
                      public static final int ROTATE_90CW = 1;
                      /*************************************************************************
                      * Represents a 180 degree rotation
                       
                      public static final int ROTATE_180 = 2;
                      public MonochromImage(int height, int width, int luminosity) {
                       
                      if(width>=0) _width=width;
                      else 
                      IntroError(ERROR_BAD_PARAM,"width is not positive");
                      if(height>=0) _height=height;
                      else
                      IntroError(ERROR_BAD_PARAM,"height is not positive");
                      if(luminosity>=0&&luminosity<=255) _luminosity=luminosity;
                      else
                      IntroError(ERROR_PARAM_BOUND,"luminosity is out of bound");
                      for(int i=0;i<_heigth;i++){
                      for(j=0;j<_width;j++)
                      {
                      _image[i][j]=liminosity;
                      }
                      }
                       
                       
                      }
                       
                      public MonochromImage(int height, int width){
                       
                      if(width>=0) _width=width;
                      else row
                      IntroError(ERROR_BAD_PARAM,"width is not positive");
                      if(height>=0) _height=height;
                      else
                      IntroError(ERROR_BAD_PARAM,"height is not positive");
                       
                      _luminosity=BG_DEFAULT;
                      for(int i=1,i<height;i++){
                      for(int j=1;j<width;j++)
                      {
                      _image[i][j]=_luminosity;
                      }
                       
                      }
                      }
                       
                      /*************************************************************************
                      *************************************************************************/
                      public MonochromImage(MonochromImage source) {
                       
                      if(source==NULL) IntroError(ERROR_GENERAL,"source is empty");
                      this(source.getWidth,source.getHieght);
                       
                       
                       
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage(int[][] data){
                       
                      image = new int[][];
                      	_image=image.setData(data);
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public int getHeight(){
                      return _height;
                       
                       
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public int getWidth()
                      return _width;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public int getValue(int row, int column){
                      if(row>_height-1||row<0)
                      IntroError(ERROR_PARM_BOUND,"the row index is out of bound");
                      if(column>_width-1||column<0)
                      IntroError(ERROR_PARAM_BOUND,"the column index is out of bound")
                      datapix=_image[row-1][column-1]; 
                      return datapix;
                      }
                       
                      /************************************************************************
                       
                      public int setValue(int row,int column, int luminosity){
                      if(((row<0)||(row>_height-1))||((column<0)||(column>_width-1)))
                      IntroError(ERROR_PARAM_BOUND);
                      if((luminosity<0)||(luminosity>255) IntroError(ERROR_PARAM_BOUND));
                      _image[row][column]=luminosity;
                      value=_image[row][column];
                      return value;
                       
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public int[][] getData(){
                      for(int i=0;i<data[i].length();i++){
                       
                      newimage = new int[_height][_width];
                      for(int i=0;i<_height;i++) {
                      for(int j=0;j<_width;j++)
                      newimage[i][j]=_image[i][j]; 
                      }
                      	return newimage;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage setData(int[][] data){
                      if(data==null) Intro2Error(GENERAL_ERROR,"data is null");
                       
                       
                       
                      for(int i=0;i<data[i].length();i++){
                       
                      tempmax=i;
                      if(tempmax>max)
                      max=tempmax;
                      }
                       
                      _width=max;
                       
                       
                      _image = new int[_height][_width];
                       
                      for(i=0;i<_height;i++) {
                      for(j=0;j<_width;j++)
                      _image[i][j]=BG_DEFAULT;
                      }
                       
                      for(int i=0;i<data.length;i++){
                      for(int j=0;j<data[j].length;j++)
                      {
                      if(data[i]][j]==null) IntroError(ERROR_PARAM_BOUND);
                      else
                      if(data[i][j]<0) _image[i][j]=0;
                      else
                      if(data[i][j]>255) _image[i][j]=255;
                      else
                      _image[i][j]=data[i][j];
                      }
                       
                       
                       
                      } 
                       
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage blur(int radius){
                       
                      	return this;
                       
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage rotate(int rotation){
                       
                      return this; 
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage flipVertical(){
                       
                      for(i=0;i<_height;i++){
                      for(j=0;j<_width/2;j++){
                      temppix=_image[i][j];
                      _image[i][j]=image[i][_width-i-1];
                      _image[i][j]=temppix;
                      }
                      }
                      	return this;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage flipHorizontal(){
                       
                      for(i=0;i<_height/2;i++) {
                      for(j=0;j<_width;j++)
                      temppix=_image[i][j];
                      _image[i][j]=_image[_height-j-1][i];
                      _image[i][j]=temppix;
                      return this;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage imprint(MonochromImage source, int row, int column){
                       
                       
                      if(source==null) return source;
                      else
                      if((row>_height)&&(column>_width)) return source;
                       
                       
                       
                       
                       
                       
                      return this;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage imprint(MonochromImage source){
                       
                      return this;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage add(MonochromImage source, int row, int column){
                       
                      return this;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage add(MonochromImage source){
                       
                      return this;
                      }
                       
                      /*************************************************************************
                       
                      *************************************************************************/
                      public MonochromImage add(int luminosity){
                       
                      	return this;
                      }
                       
                      for(int i=1;i<data[i].length();i++){
                       
                      tempmax=i;
                      if(tempmax>max)
                      max=tempmax;
                      }
                       
                      _width=max;
                      _image = new int[_height][_width];
                      for(int i=0;i<data.length;i++){
                      for(int j=0;j<data[j].length;j++)
                      {
                      if(data[i][j]<0) _image[i][j]=0;
                      else
                      if(data[i][j]>255) _image[i][j]=255;
                      else
                      _image[i][j]=data[i][j];
                       
                      for(int i=0;i<_image.length;i++){ 
                      for(j=data[j].length+1;j<_image[_width].length;j++)
                      {
                      _image[i][j]=BG_DEFAULT;
                      }
                      }
                       
                      /*************************************************************************
                      Might be a bit tricky giving ideas on this since you are using packages that I do not have.

                      Ok did you test the methods that you have written so far?

                      Comment

                      Working...