By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,034 Members | 820 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,034 IT Pros & Developers. It's quick & easy.

Tips for implementing MonochromImage class

P: 7
i need tips for implimintiing this class:
http://www.cs.huji.ac.il/~intro2cs/doc/ex4/doc/index.html
thanks
Dec 11 '06 #1
Share this Question
Share on Google+
10 Replies


P: 7
i mean for the last methods
Dec 11 '06 #2

10K+
P: 13,264
i mean for the last methods
Be more specific. What exactly do you need help with?
Dec 12 '06 #3

P: 7
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 .
Dec 12 '06 #4

10K+
P: 13,264
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.
Dec 12 '06 #5

P: 7
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.
Dec 12 '06 #6

10K+
P: 13,264
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?
Dec 12 '06 #7

P: 7
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!!
Dec 12 '06 #8

10K+
P: 13,264
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?
Dec 12 '06 #9

P: 7
Interesting. Now where are you so far with it?
i am still writing the other methods :

Expand|Select|Wrap|Line Numbers
  1.  ################## 
  2. import intro2cs.utils.*;
  3. ####################
  4.  
  5. import intro2cs.Ex4.IntroError;
  6.  
  7.  
  8. public class MonochromImage {
  9.  
  10. private int _width;
  11. private int _height;
  12. private int[][] _image;
  13. private int luminosity;
  14. public static int datapix;
  15. public static int value;
  16. public static int temppix; 
  17. public static final int ERROR_BAD_PARM= 2;
  18. public static final int ERROR_GENERAL= 1;
  19. public static final int ERROR_PARAM_BOUND= 3;
  20. public static final int ERROR_UNKNOWN= 0;
  21. public static final int BG_DEFAULT = 255;
  22. * Represents a clock-wise rotation of 90 degrees
  23. *************************************************************************/
  24. public static final int ROTATE_90CW = 1;
  25. /*************************************************************************
  26. * Represents a 180 degree rotation
  27.  
  28. public static final int ROTATE_180 = 2;
  29. public MonochromImage(int height, int width, int luminosity) {
  30.  
  31. if(width>=0) _width=width;
  32. else 
  33. IntroError(ERROR_BAD_PARAM,"width is not positive");
  34. if(height>=0) _height=height;
  35. else
  36. IntroError(ERROR_BAD_PARAM,"height is not positive");
  37. if(luminosity>=0&&luminosity<=255) _luminosity=luminosity;
  38. else
  39. IntroError(ERROR_PARAM_BOUND,"luminosity is out of bound");
  40. for(int i=0;i<_heigth;i++){
  41. for(j=0;j<_width;j++)
  42. {
  43. _image[i][j]=liminosity;
  44. }
  45. }
  46.  
  47.  
  48. }
  49.  
  50. public MonochromImage(int height, int width){
  51.  
  52. if(width>=0) _width=width;
  53. else row
  54. IntroError(ERROR_BAD_PARAM,"width is not positive");
  55. if(height>=0) _height=height;
  56. else
  57. IntroError(ERROR_BAD_PARAM,"height is not positive");
  58.  
  59. _luminosity=BG_DEFAULT;
  60. for(int i=1,i<height;i++){
  61. for(int j=1;j<width;j++)
  62. {
  63. _image[i][j]=_luminosity;
  64. }
  65.  
  66. }
  67. }
  68.  
  69. /*************************************************************************
  70. *************************************************************************/
  71. public MonochromImage(MonochromImage source) {
  72.  
  73. if(source==NULL) IntroError(ERROR_GENERAL,"source is empty");
  74. this(source.getWidth,source.getHieght);
  75.  
  76.  
  77.  
  78. }
  79.  
  80. /*************************************************************************
  81.  
  82. *************************************************************************/
  83. public MonochromImage(int[][] data){
  84.  
  85. image = new int[][];
  86.     _image=image.setData(data);
  87. }
  88.  
  89. /*************************************************************************
  90.  
  91. *************************************************************************/
  92. public int getHeight(){
  93. return _height;
  94.  
  95.  
  96. }
  97.  
  98. /*************************************************************************
  99.  
  100. *************************************************************************/
  101. public int getWidth()
  102. return _width;
  103. }
  104.  
  105. /*************************************************************************
  106.  
  107. *************************************************************************/
  108. public int getValue(int row, int column){
  109. if(row>_height-1||row<0)
  110. IntroError(ERROR_PARM_BOUND,"the row index is out of bound");
  111. if(column>_width-1||column<0)
  112. IntroError(ERROR_PARAM_BOUND,"the column index is out of bound")
  113. datapix=_image[row-1][column-1]; 
  114. return datapix;
  115. }
  116.  
  117. /************************************************************************
  118.  
  119. public int setValue(int row,int column, int luminosity){
  120. if(((row<0)||(row>_height-1))||((column<0)||(column>_width-1)))
  121. IntroError(ERROR_PARAM_BOUND);
  122. if((luminosity<0)||(luminosity>255) IntroError(ERROR_PARAM_BOUND));
  123. _image[row][column]=luminosity;
  124. value=_image[row][column];
  125. return value;
  126.  
  127. }
  128.  
  129. /*************************************************************************
  130.  
  131. *************************************************************************/
  132. public int[][] getData(){
  133. for(int i=0;i<data[i].length();i++){
  134.  
  135. newimage = new int[_height][_width];
  136. for(int i=0;i<_height;i++) {
  137. for(int j=0;j<_width;j++)
  138. newimage[i][j]=_image[i][j]; 
  139. }
  140.     return newimage;
  141. }
  142.  
  143. /*************************************************************************
  144.  
  145. *************************************************************************/
  146. public MonochromImage setData(int[][] data){
  147. if(data==null) Intro2Error(GENERAL_ERROR,"data is null");
  148.  
  149.  
  150.  
  151. for(int i=0;i<data[i].length();i++){
  152.  
  153. tempmax=i;
  154. if(tempmax>max)
  155. max=tempmax;
  156. }
  157.  
  158. _width=max;
  159.  
  160.  
  161. _image = new int[_height][_width];
  162.  
  163. for(i=0;i<_height;i++) {
  164. for(j=0;j<_width;j++)
  165. _image[i][j]=BG_DEFAULT;
  166. }
  167.  
  168. for(int i=0;i<data.length;i++){
  169. for(int j=0;j<data[j].length;j++)
  170. {
  171. if(data[i]][j]==null) IntroError(ERROR_PARAM_BOUND);
  172. else
  173. if(data[i][j]<0) _image[i][j]=0;
  174. else
  175. if(data[i][j]>255) _image[i][j]=255;
  176. else
  177. _image[i][j]=data[i][j];
  178. }
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /*************************************************************************
  185.  
  186. *************************************************************************/
  187. public MonochromImage blur(int radius){
  188.  
  189.     return this;
  190.  
  191. }
  192.  
  193. /*************************************************************************
  194.  
  195. *************************************************************************/
  196. public MonochromImage rotate(int rotation){
  197.  
  198. return this; 
  199. }
  200.  
  201. /*************************************************************************
  202.  
  203. *************************************************************************/
  204. public MonochromImage flipVertical(){
  205.  
  206. for(i=0;i<_height;i++){
  207. for(j=0;j<_width/2;j++){
  208. temppix=_image[i][j];
  209. _image[i][j]=image[i][_width-i-1];
  210. _image[i][j]=temppix;
  211. }
  212. }
  213.     return this;
  214. }
  215.  
  216. /*************************************************************************
  217.  
  218. *************************************************************************/
  219. public MonochromImage flipHorizontal(){
  220.  
  221. for(i=0;i<_height/2;i++) {
  222. for(j=0;j<_width;j++)
  223. temppix=_image[i][j];
  224. _image[i][j]=_image[_height-j-1][i];
  225. _image[i][j]=temppix;
  226. return this;
  227. }
  228.  
  229. /*************************************************************************
  230.  
  231. *************************************************************************/
  232. public MonochromImage imprint(MonochromImage source, int row, int column){
  233.  
  234.  
  235. if(source==null) return source;
  236. else
  237. if((row>_height)&&(column>_width)) return source;
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. return this;
  245. }
  246.  
  247. /*************************************************************************
  248.  
  249. *************************************************************************/
  250. public MonochromImage imprint(MonochromImage source){
  251.  
  252. return this;
  253. }
  254.  
  255. /*************************************************************************
  256.  
  257. *************************************************************************/
  258. public MonochromImage add(MonochromImage source, int row, int column){
  259.  
  260. return this;
  261. }
  262.  
  263. /*************************************************************************
  264.  
  265. *************************************************************************/
  266. public MonochromImage add(MonochromImage source){
  267.  
  268. return this;
  269. }
  270.  
  271. /*************************************************************************
  272.  
  273. *************************************************************************/
  274. public MonochromImage add(int luminosity){
  275.  
  276.     return this;
  277. }
  278.  
  279. for(int i=1;i<data[i].length();i++){
  280.  
  281. tempmax=i;
  282. if(tempmax>max)
  283. max=tempmax;
  284. }
  285.  
  286. _width=max;
  287. _image = new int[_height][_width];
  288. for(int i=0;i<data.length;i++){
  289. for(int j=0;j<data[j].length;j++)
  290. {
  291. if(data[i][j]<0) _image[i][j]=0;
  292. else
  293. if(data[i][j]>255) _image[i][j]=255;
  294. else
  295. _image[i][j]=data[i][j];
  296.  
  297. for(int i=0;i<_image.length;i++){ 
  298. for(j=data[j].length+1;j<_image[_width].length;j++)
  299. {
  300. _image[i][j]=BG_DEFAULT;
  301. }
  302. }
  303.  
  304. /*************************************************************************
  305.  
Dec 12 '06 #10

10K+
P: 13,264
i am still writing the other methods :

Expand|Select|Wrap|Line Numbers
  1.  ################## 
  2. import intro2cs.utils.*;
  3. ####################
  4.  
  5. import intro2cs.Ex4.IntroError;
  6.  
  7.  
  8. public class MonochromImage {
  9.  
  10. private int _width;
  11. private int _height;
  12. private int[][] _image;
  13. private int luminosity;
  14. public static int datapix;
  15. public static int value;
  16. public static int temppix; 
  17. public static final int ERROR_BAD_PARM= 2;
  18. public static final int ERROR_GENERAL= 1;
  19. public static final int ERROR_PARAM_BOUND= 3;
  20. public static final int ERROR_UNKNOWN= 0;
  21. public static final int BG_DEFAULT = 255;
  22. * Represents a clock-wise rotation of 90 degrees
  23. *************************************************************************/
  24. public static final int ROTATE_90CW = 1;
  25. /*************************************************************************
  26. * Represents a 180 degree rotation
  27.  
  28. public static final int ROTATE_180 = 2;
  29. public MonochromImage(int height, int width, int luminosity) {
  30.  
  31. if(width>=0) _width=width;
  32. else 
  33. IntroError(ERROR_BAD_PARAM,"width is not positive");
  34. if(height>=0) _height=height;
  35. else
  36. IntroError(ERROR_BAD_PARAM,"height is not positive");
  37. if(luminosity>=0&&luminosity<=255) _luminosity=luminosity;
  38. else
  39. IntroError(ERROR_PARAM_BOUND,"luminosity is out of bound");
  40. for(int i=0;i<_heigth;i++){
  41. for(j=0;j<_width;j++)
  42. {
  43. _image[i][j]=liminosity;
  44. }
  45. }
  46.  
  47.  
  48. }
  49.  
  50. public MonochromImage(int height, int width){
  51.  
  52. if(width>=0) _width=width;
  53. else row
  54. IntroError(ERROR_BAD_PARAM,"width is not positive");
  55. if(height>=0) _height=height;
  56. else
  57. IntroError(ERROR_BAD_PARAM,"height is not positive");
  58.  
  59. _luminosity=BG_DEFAULT;
  60. for(int i=1,i<height;i++){
  61. for(int j=1;j<width;j++)
  62. {
  63. _image[i][j]=_luminosity;
  64. }
  65.  
  66. }
  67. }
  68.  
  69. /*************************************************************************
  70. *************************************************************************/
  71. public MonochromImage(MonochromImage source) {
  72.  
  73. if(source==NULL) IntroError(ERROR_GENERAL,"source is empty");
  74. this(source.getWidth,source.getHieght);
  75.  
  76.  
  77.  
  78. }
  79.  
  80. /*************************************************************************
  81.  
  82. *************************************************************************/
  83. public MonochromImage(int[][] data){
  84.  
  85. image = new int[][];
  86.     _image=image.setData(data);
  87. }
  88.  
  89. /*************************************************************************
  90.  
  91. *************************************************************************/
  92. public int getHeight(){
  93. return _height;
  94.  
  95.  
  96. }
  97.  
  98. /*************************************************************************
  99.  
  100. *************************************************************************/
  101. public int getWidth()
  102. return _width;
  103. }
  104.  
  105. /*************************************************************************
  106.  
  107. *************************************************************************/
  108. public int getValue(int row, int column){
  109. if(row>_height-1||row<0)
  110. IntroError(ERROR_PARM_BOUND,"the row index is out of bound");
  111. if(column>_width-1||column<0)
  112. IntroError(ERROR_PARAM_BOUND,"the column index is out of bound")
  113. datapix=_image[row-1][column-1]; 
  114. return datapix;
  115. }
  116.  
  117. /************************************************************************
  118.  
  119. public int setValue(int row,int column, int luminosity){
  120. if(((row<0)||(row>_height-1))||((column<0)||(column>_width-1)))
  121. IntroError(ERROR_PARAM_BOUND);
  122. if((luminosity<0)||(luminosity>255) IntroError(ERROR_PARAM_BOUND));
  123. _image[row][column]=luminosity;
  124. value=_image[row][column];
  125. return value;
  126.  
  127. }
  128.  
  129. /*************************************************************************
  130.  
  131. *************************************************************************/
  132. public int[][] getData(){
  133. for(int i=0;i<data[i].length();i++){
  134.  
  135. newimage = new int[_height][_width];
  136. for(int i=0;i<_height;i++) {
  137. for(int j=0;j<_width;j++)
  138. newimage[i][j]=_image[i][j]; 
  139. }
  140.     return newimage;
  141. }
  142.  
  143. /*************************************************************************
  144.  
  145. *************************************************************************/
  146. public MonochromImage setData(int[][] data){
  147. if(data==null) Intro2Error(GENERAL_ERROR,"data is null");
  148.  
  149.  
  150.  
  151. for(int i=0;i<data[i].length();i++){
  152.  
  153. tempmax=i;
  154. if(tempmax>max)
  155. max=tempmax;
  156. }
  157.  
  158. _width=max;
  159.  
  160.  
  161. _image = new int[_height][_width];
  162.  
  163. for(i=0;i<_height;i++) {
  164. for(j=0;j<_width;j++)
  165. _image[i][j]=BG_DEFAULT;
  166. }
  167.  
  168. for(int i=0;i<data.length;i++){
  169. for(int j=0;j<data[j].length;j++)
  170. {
  171. if(data[i]][j]==null) IntroError(ERROR_PARAM_BOUND);
  172. else
  173. if(data[i][j]<0) _image[i][j]=0;
  174. else
  175. if(data[i][j]>255) _image[i][j]=255;
  176. else
  177. _image[i][j]=data[i][j];
  178. }
  179.  
  180.  
  181.  
  182.  
  183.  
  184. /*************************************************************************
  185.  
  186. *************************************************************************/
  187. public MonochromImage blur(int radius){
  188.  
  189.     return this;
  190.  
  191. }
  192.  
  193. /*************************************************************************
  194.  
  195. *************************************************************************/
  196. public MonochromImage rotate(int rotation){
  197.  
  198. return this; 
  199. }
  200.  
  201. /*************************************************************************
  202.  
  203. *************************************************************************/
  204. public MonochromImage flipVertical(){
  205.  
  206. for(i=0;i<_height;i++){
  207. for(j=0;j<_width/2;j++){
  208. temppix=_image[i][j];
  209. _image[i][j]=image[i][_width-i-1];
  210. _image[i][j]=temppix;
  211. }
  212. }
  213.     return this;
  214. }
  215.  
  216. /*************************************************************************
  217.  
  218. *************************************************************************/
  219. public MonochromImage flipHorizontal(){
  220.  
  221. for(i=0;i<_height/2;i++) {
  222. for(j=0;j<_width;j++)
  223. temppix=_image[i][j];
  224. _image[i][j]=_image[_height-j-1][i];
  225. _image[i][j]=temppix;
  226. return this;
  227. }
  228.  
  229. /*************************************************************************
  230.  
  231. *************************************************************************/
  232. public MonochromImage imprint(MonochromImage source, int row, int column){
  233.  
  234.  
  235. if(source==null) return source;
  236. else
  237. if((row>_height)&&(column>_width)) return source;
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244. return this;
  245. }
  246.  
  247. /*************************************************************************
  248.  
  249. *************************************************************************/
  250. public MonochromImage imprint(MonochromImage source){
  251.  
  252. return this;
  253. }
  254.  
  255. /*************************************************************************
  256.  
  257. *************************************************************************/
  258. public MonochromImage add(MonochromImage source, int row, int column){
  259.  
  260. return this;
  261. }
  262.  
  263. /*************************************************************************
  264.  
  265. *************************************************************************/
  266. public MonochromImage add(MonochromImage source){
  267.  
  268. return this;
  269. }
  270.  
  271. /*************************************************************************
  272.  
  273. *************************************************************************/
  274. public MonochromImage add(int luminosity){
  275.  
  276.     return this;
  277. }
  278.  
  279. for(int i=1;i<data[i].length();i++){
  280.  
  281. tempmax=i;
  282. if(tempmax>max)
  283. max=tempmax;
  284. }
  285.  
  286. _width=max;
  287. _image = new int[_height][_width];
  288. for(int i=0;i<data.length;i++){
  289. for(int j=0;j<data[j].length;j++)
  290. {
  291. if(data[i][j]<0) _image[i][j]=0;
  292. else
  293. if(data[i][j]>255) _image[i][j]=255;
  294. else
  295. _image[i][j]=data[i][j];
  296.  
  297. for(int i=0;i<_image.length;i++){ 
  298. for(j=data[j].length+1;j<_image[_width].length;j++)
  299. {
  300. _image[i][j]=BG_DEFAULT;
  301. }
  302. }
  303.  
  304. /*************************************************************************
  305.  
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?
Dec 12 '06 #11

Post your reply

Sign in to post your reply or Sign up for a free account.