Question regarding std::Vector....
-
Hi, I am working with images and computing radon transform for an object. the function that computes the transform accepts vector as input:
pixel p;
vector segObj //segObj is the object segmneted from the imagepixel is a user-defined struct defined as:
struct pixel
{
float x, y; //x,y coordinates of the pixel
};Currently, I am doing an element wise assignment to the vector:
for(int ix=0; ix < element_count; ix++)
{
{
f.x = xCoordArray[ix];
f.y = yCoordArray[ix];
segObj.push_back(f);
}
}//xCoordArray and yCoordArray are computed separately The for loop makes it slow when dealing with large images. Is there a way to assign xCoordArray and yCoordArray directly to
vectorsegObj
I am not expereinced with the use of vectors so any help would be appreciated Thanks
-
Hi, I am working with images and computing radon transform for an object. the function that computes the transform accepts vector as input:
pixel p;
vector segObj //segObj is the object segmneted from the imagepixel is a user-defined struct defined as:
struct pixel
{
float x, y; //x,y coordinates of the pixel
};Currently, I am doing an element wise assignment to the vector:
for(int ix=0; ix < element_count; ix++)
{
{
f.x = xCoordArray[ix];
f.y = yCoordArray[ix];
segObj.push_back(f);
}
}//xCoordArray and yCoordArray are computed separately The for loop makes it slow when dealing with large images. Is there a way to assign xCoordArray and yCoordArray directly to
vectorsegObj
I am not expereinced with the use of vectors so any help would be appreciated Thanks
-
-
There is a little improvement but for cases with more coordiante values ( > 2000) it is still slow. I am trying to get rid of the for loop, since at each index there a two values (pixel coordinates) using .assign is a bit tricky for me thanks
If speed is a concern to you, you must use
xCoordArray
andyCoordArray
as is without using thevector
.«_Superman_» _I love work. It gives me something to do between weekends.
-
If speed is a concern to you, you must use
xCoordArray
andyCoordArray
as is without using thevector
.«_Superman_» _I love work. It gives me something to do between weekends.
-
Hi, I am working with images and computing radon transform for an object. the function that computes the transform accepts vector as input:
pixel p;
vector segObj //segObj is the object segmneted from the imagepixel is a user-defined struct defined as:
struct pixel
{
float x, y; //x,y coordinates of the pixel
};Currently, I am doing an element wise assignment to the vector:
for(int ix=0; ix < element_count; ix++)
{
{
f.x = xCoordArray[ix];
f.y = yCoordArray[ix];
segObj.push_back(f);
}
}//xCoordArray and yCoordArray are computed separately The for loop makes it slow when dealing with large images. Is there a way to assign xCoordArray and yCoordArray directly to
vectorsegObj
I am not expereinced with the use of vectors so any help would be appreciated Thanks
you could try:
segObj.resize(element_count);
for(int ix=0; ix < element_count; ix++)
{
segObj[ix].x = xCoordArray[ix];
segObj[ix].y = yCoordArray[ix];
}that eliminates the push_back, at least.