Yes, at least for me. In your OP lines 17..21 are:
1 2 3 4 5
|
if (height < map[r][c].r){
return;
}
tempVar = map[r][c].r;
|
Questions: You have a grey scale image consisting of RGB values? Black is RGB = {0, 0, 0} and white is RGB = {FF, FF, FF}? In that case it is OK to use R as substitute, you just stop at the red line ;)
Are the "valleys" you try to fill with green areas brighter/clearer than the surrounding "heights"? Then you should rethink why you refuse filling
if (height < map[r][c].r) -- if the pixel in question is brighter than the darker border, do not stop, paint it green. Otherwise (the "sink" is dark, the "dam" is bright) the
return is correct for the pixel in question.
Then -- I ask again -- you query the current pixel's red component, set tempVar with it,
tempVar = map[r][c].r;
and use just this tempVar as third argument for the recursive call treating the eight surrounding pixel. There this third argument is the new dam altitude. So if the current pixel is white (synonymical to R=FF) you set the border for the adjunct pixels to white. If you are filling a white plane, it is just the comparison
< instead of
<= in line 17 that
by chance still
could make it work. If the variable height is part of the assignment, this request is not very reasonable, or worded mistakable -- as always: "It ain't my fault."
In addition, if you deal with gray scale images you should consider the suggestion of ne555
(height+tolerance < map[r][c].r) return;