hi
i want to modify cells of image
how can i access to element of an image and modify it
so thanks
how can i access to element of an image and modify it
Re: how can i access to element of an image and modify it
It's Simple. If you have an image
You can obtain the value on the (x, y) position by calling
To set the color, call
Code: Select all
Image<Bgr^, Byte>^ img;
Code: Select all
Bgr^ color = img[y,x];
Code: Select all
img[y,x] = color
-
- Posts: 3
- Joined: Fri Sep 26, 2008 4:14 am
Re: how can i access to element of an image and modify it
Hi, I have the same problem!
I have to tranlsate this C++ OpenCv code
for( int i = 1; i < mask->width-1; i++ )
for( int j = 1; j < mask->height-1; j++ )
{
uchar idx = CV_IMAGE_ELEM( mask, uchar, j, i );
if(idx==255){
uchar blue = CV_IMAGE_ELEM( color_img0, uchar, j-1, (i-1)*3);
uchar green = CV_IMAGE_ELEM( color_img0, uchar, j-1, (i-1)*3 +1);
uchar red = CV_IMAGE_ELEM( color_img0, uchar, j-1, (i-1)*3 +2);
(uchar) CV_IMAGE_ELEM( color_imgSelected, uchar, j-1, (i-1)*3)= blue;
(uchar) CV_IMAGE_ELEM( color_imgSelected, uchar, j-1, (i-1)*3+1)= green;
(uchar) CV_IMAGE_ELEM( color_imgSelected, uchar, j-1, (i-1)*3+2)= red;
}
}
into C# Emgu code. I wrote:
for (int i = 1; i < mask.Width - 1; i++)
for (int j = 1; j < mask.Height - 1; j++)
{
Gray idx = mask[j, i];
if (idx.Intensity == 255)
{
imageSelected[j - 1, (i - 1)] = originalImage[j - 1, (i - 1)];
}
}
It works, but it is very very slow!!!
It seems that accessing pixels takes a lot of time. Instead in Opencv this operation is much more fast!!
Or I do something wrong!
Any help?
Thank you very very much!!!
I have to tranlsate this C++ OpenCv code
for( int i = 1; i < mask->width-1; i++ )
for( int j = 1; j < mask->height-1; j++ )
{
uchar idx = CV_IMAGE_ELEM( mask, uchar, j, i );
if(idx==255){
uchar blue = CV_IMAGE_ELEM( color_img0, uchar, j-1, (i-1)*3);
uchar green = CV_IMAGE_ELEM( color_img0, uchar, j-1, (i-1)*3 +1);
uchar red = CV_IMAGE_ELEM( color_img0, uchar, j-1, (i-1)*3 +2);
(uchar) CV_IMAGE_ELEM( color_imgSelected, uchar, j-1, (i-1)*3)= blue;
(uchar) CV_IMAGE_ELEM( color_imgSelected, uchar, j-1, (i-1)*3+1)= green;
(uchar) CV_IMAGE_ELEM( color_imgSelected, uchar, j-1, (i-1)*3+2)= red;
}
}
into C# Emgu code. I wrote:
for (int i = 1; i < mask.Width - 1; i++)
for (int j = 1; j < mask.Height - 1; j++)
{
Gray idx = mask[j, i];
if (idx.Intensity == 255)
{
imageSelected[j - 1, (i - 1)] = originalImage[j - 1, (i - 1)];
}
}
It works, but it is very very slow!!!
It seems that accessing pixels takes a lot of time. Instead in Opencv this operation is much more fast!!
Or I do something wrong!
Any help?
Thank you very very much!!!
-
- Posts: 3
- Joined: Fri Sep 26, 2008 4:14 am
Re: how can i access to element of an image and modify it
I solved the problem in this way:
MCvScalar indx = CvInvoke.cvGet2D(mask, j, i);
if (indx.v0 == 255)
{
MCvScalar newColor = CvInvoke.cvGet2D(originalImage, j - 1, i - 1);
CvInvoke.cvSet2D(imageSelected, j - 1, i - 1, newColor);
}
inside the 2 for.
Now it works very fast!!
MCvScalar indx = CvInvoke.cvGet2D(mask, j, i);
if (indx.v0 == 255)
{
MCvScalar newColor = CvInvoke.cvGet2D(originalImage, j - 1, i - 1);
CvInvoke.cvSet2D(imageSelected, j - 1, i - 1, newColor);
}
inside the 2 for.
Now it works very fast!!
Re: how can i access to element of an image and modify it
If mask contain only values of either 0 or 255, the following call would be THE FASTEST (and use fewest code):
If the mask contains values other than 0 or 255, then apply threshold on the mask first.
Code: Select all
imageSelected = originalImage.Copy(mask);