473,396 Members | 1,738 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,396 software developers and data experts.

pls explain the "for loops x 4"

there are two 2d array
1st one has height and width
2nd one has elHeight and elWidth
vCenter and hCenter are the center of the 2nd 2d array

I don't understand these code. Anybody understand how the 2nd array moves over the 1st array and change the value of the element pixel?? What does indRow and indCol represent??

Expand|Select|Wrap|Line Numbers
  1. 94 /**
  2. 95 * Gets the value at a given pixel. The row and column numbering
  3. 96 * starts at zero.
  4. 97 * @param row The row-number of the pixel.
  5. 98 * @param col The column-number of the pixel.
  6. 99 * @return true if the pixel's bit is 1 otherwhise false.
  7. 100 */
  8. 101 public boolean getValueAt(int row, int col)
  9. 102 {
  10. 103 int index = row*width + col;
  11. 104 return data.get(index);
  12. 105 }
  13. 106
  14. 107
  15. 108 /**
  16. 109 * Sets the value at a given pixel as true or false (representing 1 or 0).
  17. 110 * @param row The row-number of the pixel.
  18. 111 * @param col The column-number of the pixel.
  19. 112 */
  20. 113 public void setValueAt(int row, int col, boolean value)
  21. 114 {
  22. 115 int index = row*width + col;
  23. 116 data.set(index, value);
  24. 117 }
  25. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  26.       int indRow, indCol;
  27.  
  28.       for (int row = 0; row < height; row++)
  29.       {
  30.          for (int col = 0; col < width; col++)
  31.          {
  32.  
  33.             if (image.getValueAt (row, col))
  34.             {
  35.  
  36.                for (int i = 0; i < elHeight; i++)
  37.                {
  38.                   for (int j = 0; j < elWidth; j++)
  39.                   {
  40.                      indRow = row + i - vCenter;
  41.                      indCol = col + j - hCenter;
  42.  
  43.                      if (rStructMatrix[i][j] == 1 &&
  44.                          indRow >= 0 && indRow < height &&
  45.                          indCol >= 0 && indCol < width)
  46.                      {
  47.                         dilatedImage.setValueAt (indRow, indCol, true);
  48.                      }
  49.                   }
  50.                }
  51.  
  52.             }// end if
  53.  
  54.          }
  55.       }
  56.  
  57.       return dilatedImage;
  58.    }
Apr 1 '07 #1
2 1058
r035198x
13,262 8TB
there are two 2d array
1st one has height and width
2nd one has elHeight and elWidth
vCenter and hCenter are the center of the 2nd 2d array

I don't understand these code. Anybody understand how the 2nd array moves over the 1st array and change the value of the element pixel?? What does indRow and indCol represent??

Expand|Select|Wrap|Line Numbers
  1. 94 /**
  2. 95 * Gets the value at a given pixel. The row and column numbering
  3. 96 * starts at zero.
  4. 97 * @param row The row-number of the pixel.
  5. 98 * @param col The column-number of the pixel.
  6. 99 * @return true if the pixel's bit is 1 otherwhise false.
  7. 100 */
  8. 101 public boolean getValueAt(int row, int col)
  9. 102 {
  10. 103 int index = row*width + col;
  11. 104 return data.get(index);
  12. 105 }
  13. 106
  14. 107
  15. 108 /**
  16. 109 * Sets the value at a given pixel as true or false (representing 1 or 0).
  17. 110 * @param row The row-number of the pixel.
  18. 111 * @param col The column-number of the pixel.
  19. 112 */
  20. 113 public void setValueAt(int row, int col, boolean value)
  21. 114 {
  22. 115 int index = row*width + col;
  23. 116 data.set(index, value);
  24. 117 }
  25. //////////////////////////////////////////////////////////////////////////////////////////////////////////
  26. int indRow, indCol;
  27.  
  28. for (int row = 0; row < height; row++)
  29. {
  30. for (int col = 0; col < width; col++)
  31. {
  32.  
  33. if (image.getValueAt (row, col))
  34. {
  35.  
  36. for (int i = 0; i < elHeight; i++)
  37. {
  38. for (int j = 0; j < elWidth; j++)
  39. {
  40. indRow = row + i - vCenter;
  41. indCol = col + j - hCenter;
  42.  
  43. if (rStructMatrix[i][j] == 1 &&
  44. indRow >= 0 && indRow < height &&
  45. indCol >= 0 && indCol < width)
  46. {
  47. dilatedImage.setValueAt (indRow, indCol, true);
  48. }
  49. }
  50. }
  51.  
  52. }// end if
  53.  
  54. }
  55. }
  56.  
  57. return dilatedImage;
  58. }
Where did you get the code? The answers to your questions should be found where you got the code.
Apr 2 '07 #2
hirak1984
316 100+
I think this is an incomplete code!!!

where is width defined and gets its value?
please post if I am incorrect...
Apr 2 '07 #3

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

Similar topics

23
by: Invalid User | last post by:
While trying to print a none empty list, I accidentaly put an "else" statement with a "for" instead of "if". Here is what I had: if ( len(mylist)> 0) : for x,y in mylist: print x,y else:...
11
by: David Morgenthaler | last post by:
How does one overide the iterator implied by the construct "for line in file:"? For example, suppose I have a file containing row,col pairs on each line, and I wish to write a subclass of file...
15
by: adomas.paltanavicius | last post by:
Hi there, I am quite new to Python, and have a straight & simple question. In C, there is for (init; cond; advance). We all know that. In Python there are two ways to loop over i=A..B...
9
by: adam | last post by:
hello Does exist in SQL language "for" loop ? If yes, what syntax does it has ? best wishes Adam
0
by: juliane26 | last post by:
Being new on z/OS for some time I do have some problems with Explain. I tried the Visual Explain for z/OS, but since we use Version 7 database I can't even see the join predicates or any cost...
32
by: Toby Newman | last post by:
At the page: http://www.strath.ac.uk/IT/Docs/Ccourse/subsection3_8_3.html#SECTION0008300000000000000 or http://tinyurl.com/4ptzs the author warns: "The for loop is frequently used, usually...
5
by: Fabian Vilers | last post by:
Hi again... I'm wondering what could be better in terms of performance between: var my_array = new Array(); // populate array for (index in my_array) { // do something with my_array
34
by: Frederick Gotham | last post by:
Is the domestic usage of the C "for" loop inefficient when it comes to simple incrementation? Here's a very simple program that prints out the bit-numbers in a byte. #include <stdio.h> #include...
4
by: MDR | last post by:
Hello I have three "for" loops, two nested into the outer one and they depend on each other, like this: for (x=1; x<100; x++) { .... for (i=1; i<10; i++) {....} for (j=1; j<10;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.