Ask Your Question
-1

Displaying images from 1D double array

asked 2018-02-21 12:54:15 -0600

HebaKM gravatar image

updated 2018-02-22 05:14:46 -0600

I have a 1D double array that represents a grayscale image. How can I create a Mat using this array to display the image using imshow?

Mat img = imread("input.jpg",0);
double outImg[224932];
imgProcessing(src.data,outImg);

The following are the processing fuctions:

static double* imgProcessing(unsigned char* data)
{
    double *img = filter(data);
    return img ;
}

double* filter(const unsigned char imageName[680028])
{
  int i0;
  static double img[680028];
  static double img_x[680028];
  static double img_y[680028];
  static double img_sqr[680028];

  static double test[680028];
  for (i0 = 0; i0 < 680028; i0++) {
    img[i0] = (double)imageName[i0] / 255.0;
  }

  imfilter(img, img_x);
  b_imfilter(img, img_y);
  power(img_x, img_sqr);
  power(img_y, img);
  for (i0 = 0; i0 < 680028; i0++) {
    imgl_sqr[i0] += img[i0];
  }

  b_sqrt(img_sqr);
  return img_sqr;
 }

Thanks in advance.

edit retag flag offensive close merge delete

Comments

1
  • do you know width and height of that image ?
  • where is that array coming from ? will it stay alive ? (pointer ownership)
berak gravatar imageberak ( 2018-02-21 13:00:23 -0600 )edit

Yes, the height and width of the image are known. This is an array that was returned from a function that processes a given image to detect edges.

HebaKM gravatar imageHebaKM ( 2018-02-21 13:15:43 -0600 )edit

"This is an array that was returned from a function that processes a given image" -- so, some kind of callback function ?

could you add the code, acquiring the image ?

(again, the question is: do we need to copy the data, or not, will it go out of scope (between imshow() / waitKey() calls) ? then we need to.)

berak gravatar imageberak ( 2018-02-21 13:18:20 -0600 )edit
1

I have added what I have come up with till now. The code was written in the main function. Then, from there I called the imgProccessing function. Yes, I do need to copy the data.

HebaKM gravatar imageHebaKM ( 2018-02-21 13:32:21 -0600 )edit

you probably should not write code like this, but use opencv functions instead.

berak gravatar imageberak ( 2018-02-22 05:35:22 -0600 )edit

I am required to use this could, I can not use opencv fucntions.

HebaKM gravatar imageHebaKM ( 2018-02-22 07:46:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-21 13:47:22 -0600

berak gravatar image

updated 2018-02-21 13:50:03 -0600

so, it'll be:

double * pointer =  ... // to_some_imgdata ?
int H = height ?? 
int W = width ?? 
Mat mat (H, W, CV_64F, pointer).clone(); // clone == copy the actual pixel data

// now this is the real "easy" part !
imshow( "lalaland", mat);
waitKey(); // wait "forever," until any key was pressed, while this window has focus)
edit flag offensive delete link more

Comments

Thank you very much, Berak. I tried your idea, it worked but the image created seams to be duplicated three times for some reason.

HebaKM gravatar imageHebaKM ( 2018-02-22 04:45:49 -0600 )edit

so, check again, where your data comes from. is it really grayscale, single channel ?

we can only try to help, based on the information you give.

please show your processing function

berak gravatar imageberak ( 2018-02-22 04:53:05 -0600 )edit

The input image is a grayscale image. I am supposed to pass it into a filter that returns a grayscale image after applying the filter.

HebaKM gravatar imageHebaKM ( 2018-02-22 05:18:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-02-21 12:54:15 -0600

Seen: 711 times

Last updated: Feb 22 '18