Custom Algorithms
continuation of bitmaps
Last updated
continuation of bitmaps
Last updated
this is the continuation of Now we want to count the pixels and divide them in 3 areas and find which ones are orange...
String[] possiblePos = {"left", "middle", "right"};
: This array holds the possible positions of the cone, assuming there are three positions: left, middle, and right.
List<int[]> rgb = rgbValues;
: This line creates a new List (rgb
) and initializes it with the provided rgbValues
list, which contains RGB values of pixels from an image.
int size = rgb.size();
: It calculates the total number of RGB values (pixels) in the rgb
list.
int section = size/3;
: This variable section
determines the number of pixels that belong to each possible position (left, middle, right). The size
of rgb
is divided by 3 because we are assuming three possible positions.
List<Integer> sum = new ArrayList<Integer>(3);
: This creates a new List (sum
) to store the count of pixels that belong to each possible position (left, middle, right).
sum.add(0); sum.add(0); sum.add(0);
: It initializes the sum
list with three elements, all set to 0. Each element represents the count of pixels for the corresponding position.
int indx = 0;
: This variable indx
is used to iterate through the rgb
list.
The while
loop iterates through all the RGB values in the rgb
list.
int[] pixel = rgb.get(indx);
: This line retrieves the RGB values of a pixel from the rgb
list.
The if
condition checks if the RGB values of the pixel fall within specific color ranges, suggesting the presence of a cone. If the conditions are met, it increments the corresponding section's pixel count in the sum
list.
After the loop, maxIndx
is calculated, which represents the index of the position (left, middle, right) with the highest pixel count in the sum
list.
If all pixel counts in the sum
list are 0, it indicates that there is no cone detected, and the method returns -1. Otherwise, it prints the detected cone's position and returns the index of the cone's position (maxIndx
).
In summary, this method processes RGB values of pixels from an image and determines the position of a cone based on certain color ranges in the RGB values. The position with the highest number of pixels falling within the specified color ranges is considered the cone's position. If no cone is detected, it returns -1.