views:

367

answers:

4

Hi, i am searching for a smart solution for this problem:

A cancer ct picture is stored inside a unsigned short array (1-dimensional).

I have the location information of the cancer region inside the picture, but the coordinates (x,y) are in superpixel (128x128 unsigned short). My task is to highlight this region.

I already solved this one by converting superpixel coordinates into a offset a can use for the unsigned short array. It works fine but i wonder if there is a smarter way to solve this problem, since my solution needs 3 nested for-loops.

Is it possible to access the ushort array "superpixelwise", so i can navigate the ushort array in superpixels.

...

// i know this does no work ... just to give you an idea what i was thinking of ... 

typedef struct 
{
   unsigned short[128x128]
} 
spix;

spix *spixptr;

unsigned short * bufptr = img->getBuf();

spixptr = bufptr;

...

best regards,

zhengtonic

+1  A: 

This is difficult to answer, since it's rather vague.

If you only mean "how do I access a pixel at (x,y) given this definition of an image", the answer shouldn't be very surprising:

typedef struct
{
    unsigned short data[128 * 128]; // This was broken in the question.
} spix;


void spix_set_pixel(spix *s, unsigned int x, unsigned int y, unsigned short value)
{
  s->data[y * 128 + x] = value;
}

Not sure at all if this answers your question, but it sounds ... plausible, at least.

unwind
A: 

yep its vague, let me try again with a picture :)

[0][1][2] ... [127]| ... [x] |
[1]                |         |
[2]                |         |
.                  |         |
.                  | <-- this is a superpixel
.                  |         |
[127]              |         |
--------------------         |
.                            |
.                            |
.                            |
[y]                          |<--whole picture stored in a ushort* buf = new ushort[x*y]
------------------------------

i like to access the 128x128 ushorts at once with a pointer, so i can memcpy data into the 128x128 field.

zhengtonic
Would be good if you moved this into the question so it won't get lost here in the answers.
Daemin
This is not possible, as long as your image is stored in 2D like you show. There is no way for mempcy() to know that it should skip the rest of the superpixels, once it's finished with the subpixels of a single row.
unwind
No, but this is C++ and you can create a class with all of the required operations on it that would allow you to effectively work with superpixels.
Daemin
A: 

From what I understand you have:

  • A large image that is a CT scan
  • A rectangular area within that image that is a cancer

Then it gets a bit harder to understand. I believe you want to create some sort of class so that you can effectively access 128x128 blocks of the image as if they were a single pixel.

So if the image was 1024x1024 pixels you'd want to be able to access it as a 8x8 grid of 128x128 pixel blocks. Now if this is the case what you need is to create a class that represents one of these 128x128 blocks. This class should reference the image, so that you don't copy the image data, and should contain all of the operations that you'd want to do on that "superpixel".

However if all you want to do is to be able to extract out a particular 128x128 block from the larger image then what you need is the bit blit algorithm. The bit block transfer (usually called just blit) will allow you to copy the selected bit of data from the larger image to a smaller one. The algorithm can also be adapted to do almost anything you want to a particular area in the larger image.

If a blit is all you need then every relatively modern graphics API should have blit function(s).

Daemin
A: 

Thx a lot guys! The bitblit transfer hint helped a lot!

best regards,

zhengtonic

zhengtonic