This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
Greetings,
Please refer this link to the images.
I have an image that is my source. I need to duplicate this image and place it nearby, at a particular distance and calculate the total number of pixels. The number of copies is a variable. Distance at which the copies will be place will be calculated by code. The copies placed nearby may or may not overlap the original or other copies.
Source file for this example has 8260 black pixels. when 3 extra copies are made but there is no overlapping, black pixels are 33040 in number. When 3 extra copies are made and they do overlap, the black pixels are 31888 in numbers. In the end, I'm not interested in the final image, I want the pixel count.
My program will perform 8000 of such placements and do the pixel count 8000 times. Hence I need to find a proper and fast way to do it.
Before this, I used to do it another way. Because Octagon, Circle, square are simple figures, and it was just the number of pixels, I used no image at all. Following is a logic I used to count pixels in an octagon.
Area.resize(ArrayRowSize 5, std::vector<int>(ArrayColSize 5, 0));
for (i = 0; i < NoOfShapesLeftToRight; i )
{
for (j = 0; j < NoOfShapesTopToBottom; j )
{
for (x = A - G; x < A G; x )
{
for (y = B - G; y < B G; y )
{
if ((x - y >= A - B - S - G) && (y <= B G) && (x y <= A B S G) && (x <= A G) && (x - y <= A G - B S) && (y >= B - G) && (x y >= A B - S - G) && (x >= A - G)) //condition to check bounds of a octagon, equation is easy for circle and not needed for a square.
{
Area[x][y] = 1;
ArrayRowSize and ArrayColSize are the calculated height and width respectively of the image. NoOfShapesLeftToRight and NoOfShapesTopToBottom are both 2 in the example given above. In the end I used to count number of 1's in array and that's my no of pixels.
In future I have to deal with shapes that do not have specific equations and inputting them as images might be the best idea. Hence I'm looking at a way to do it with overlapping images.
Subreddit
Post Details
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cpp_questio...