473,324 Members | 2,002 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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
Dec 11 '06 #1
10 1146
i mean for the last methods
Dec 11 '06 #2
r035198x
13,262 8TB
i mean for the last methods
Be more specific. What exactly do you need help with?
Dec 12 '06 #3
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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

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

Similar topics

4
by: Serge Calderara | last post by:
dear all, when I use classes function from framework, I could see a small tooltips wich is showing parameters to pass to the function but in addition a brief derscription of each. When doing...
1
by: Maurice | last post by:
Hi, We are implementing some wrappers in C++ according to the Adapter Pattern. The classes and their methods in the Adaptee classes (open-source library) have already the interface that we like,...
6
by: Martyn Lawson | last post by:
Hi, I am currently working as an Analyst on a .NET Web Project using ASP.NET and C#.NET. I have a couple of, at least what should be, quick questions: 1. My understanding of UML says that...
3
by: Frans Bouma | last post by:
Hi, I have a serious problem with VB.NET and a DataTable derived class and I can't figure out how to solve it. I have implemented it in C# where it works perfectly, but I can't port one...
28
by: Yuri CHUANG | last post by:
"No newline at the end of your output" is really a problem? I've never learned that before. So I desire to know some tips about writting a program perfectly.Can anyone give me some tips which are...
4
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue,...
31
by: JoeC | last post by:
I have read books and have ideas on how to create objects. I often create my own projects and programs. They end up getting pretty complex and long. I often use objects in my programs they are...
6
by: Joseph Geretz | last post by:
I have the following class which I am serializing and passing back and forth between my Web Service application and the client. public class Token : SoapHeader { public string SID; public...
5
by: koonda | last post by:
Hi all, I am a student and I have a project due 20th of this month, I mean May 20, 2007 after 8 days. The project is about creating a Connect Four Game. I have found some code examples on the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.