This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Using "Connected Components Labeling" on large images

Hi,

I am using the VLIB library's "Create Connected Components List" on an image to extract information about blobs.

I'm building on the VLIB_testConnectedComponents.c example, and got everything to work with my own 32-bit packed binary converted image (in a small size).

The problem comes when I increase the size of my image. Already at sizes over 64x225 pixels, the VLIB_createConnectedComponentsList returns an error, and for sizes over 200x200 the execution won't even start.
I have lowered the maxBytesRequired, as recommended, to around 32000. This seems to be the max size that VLIB_initConnectedComponentsList accepts.

Cut to the chase: I need to analyse a large image (over 320x320 pixels), but VLIB_createConnectedComponentsList keeps returning != 0 (which is equal to error).

Here's the crucial part of the code:


#define DDR2HEAP   0
#define MINBLOBAREA 50
#define IMAGEWIDTH  320
#define IMAGEHEIGHT 320   
#define NUM32BITPACKEDBINARYWORDSperROW IMAGEWIDTH/32

#pragma DATA_SECTION(binary32bitPackedFGMask, "ddr2")
int  binary32bitPackedFGMask[IMAGEHEIGHT][NUM32BITPACKEDBINARYWORDSperROW];

...

void main(void)
{

    void *pBuf;
    VLIB_CCHandle * handle;
    VLIB_CC         vlibBlob;
   
    ...

    #define MEM_alloc(x,y,z) malloc(y)

    VLIB_calcConnectedComponentsMaxBufferSize(IMAGEWIDTH,IMAGEHEIGHT,MINBLOBAREA,&maxBytesRequired);

    //bytesRecommended = maxBytesRequired/2;
    bytesRecommended = 32000;

    // Manage handle
    sizeOfCCHandle =  VLIB_GetSizeOfCCHandle(); 
    handle = (VLIB_CCHandle *) MEM_alloc(DDR2HEAP, sizeOfCCHandle, 8);

    // Set-up Memory Buffers
    pBuf    = (void *)  MEM_alloc(DDR2HEAP, bytesRecommended, 8);
    statusInit    = VLIB_initConnectedComponentsList(handle, pBuf, bytesRecommended);

    ...
    //Packing my image correctly to binary32bitPackedFGMask
    ...

    status = VLIB_createConnectedComponentsList(handle,
             IMAGEWIDTH,
             IMAGEHEIGHT,
             (int*)(&binary32bitPackedFGMask[0][0]),
             MINBLOBAREA,
             1);

    if (status != VLIB_NO_ERROR)
        printf("\nCreation of Connected Components failed!!!");

    ...


Why can't the process accept bigger images then 64x225 pixels. Can anybody help me find the bottleneck? Could it be memory usage?

The image is located in extern memory and I'm using CCS 3.3 on a DM6437.

Hope my question makes sense,

Martin

  • Does either malloc return a NULL pointer?  If so, you'll need to increase the heap space with the -heap linker option.

    Does VLIB_createConnectedComponentsList return distinct values for distinct errors?  If so, it would be instructive to know which one it's returning.

  • Oh, I forgot to write what errors they returned.

    VLIB_initConnectedComponentsList() returns 6 = VLIB_ERR_MEMORY_POINTER_NULL, when the "bytesRecommended" is too high.

    and

    VLIB_createConnectedComponentsList() returns 5 = VLIB_ERR_MEMORY_ALLOCATION_FAILURE, when the array/image dimension is too big.

    So you are absolutely right Archaeologist. I tried to increase my heap space and it makes the situation better. I can now analyze an image of 320x90 pixels, with a heap size of 0x00012500. But I'm hitting the wall here. I'm literally running out of allocation space. Aiming at analyzing an image of at least 320x320 pixels, means the need of a massive heap.

    Why is there a need for so much space? Is there anything wrong with placing it in extern memory?

    btw I'm not using DSP/BIOS in this project.

    Thanks,
    Martin

  • Martin R said:

    Why is there a need for so much space? Is there anything wrong with placing it in extern memory?

    Sorry, I'm not familiar with VLIB.  Perhaps the documentation will tell you exactly why it needs to allocate that much.

    It should be legal to place pBuf in extern memory.  Since you know the exact size at compile time, you might consider instead replacing it with a static array, assuming you don't need to reclaim the space for another algorithm.  The memory allocated by VLIB_createConnectedComponentsList() is probably not under your control, so to accomplish having that data in extern memory, you'll probably need to put the whole heap there.

    Placing it in extern memory may make it significantly slower, depending on how you have your memory set up.  Sorry, I'm not at all an expert on correctly managing external memory speed.

     

  • I solved the problem by placing my .sysmem in extern memory. Thereby I could increase the heap space and analyse larger images. Think it also results in the fastest method.

     

    Thanks for the help...