1

im doing my final project using CVI and i have some problems. the project in general is to apply FFT on an image, add white gaussian noise at four levels (channel), apply an IFFT to restore the original image. i have two parts:

  1. i can use 2DFFT or 1DFFT for rows and than columns
  2. i must use 1DFFT for rows and than columns and pass the signals through filters 2D-DWT

Right now im saving the image data with a pointer called bitmapID which can only be use at some functions. I would like to save the image data as an array so it will be easier for me to access it and do the manipulations. I tried use the function ImaqImageToArray, but i dont know why it isnt working (something related to the dimensions of the image)

I would like to get some help with it Thanks in advance

here some of the things that i have been trying:

#include "nivision.h"
#include <advanlys.h>
#include <formatio.h>
#include <ansi_c.h>
#include <cvirte.h>     
#include <userint.h>
#include "Project.h"

static int __F_boGet_And_Display_User_Image(void)
{
    char FileName[260];
    int status;
    AnalysisLibErrType analysisErr;
    //int fit_mode;
    
    //prompt user to select file
    status = FileSelectPopup ("", "*.jpg", "", "", VAL_LOAD_BUTTON, 0, 0, 1, 1, FileName);
    if(status == VAL_NO_FILE_SELECTED)
        return(FALSE);
    
    //-------------------------------------------------------------------------
                
    //get image bitmap id
    status = GetBitmapFromFile (FileName, &bmpHandler);
    if(status != UIENoError)
    {
        __F_voError("Failed to get image file bitmap" , FileName);
        return(FALSE);
    }
        
    //display image on panel
    FitModeControl_Callbak(panelHandle,PANEL_CHECKBOX_FIT_MODE,EVENT_COMMIT,NULL,0,0);
    DisplayImageFile(panelHandle,PANEL_PICTURE_ORIGINAL,FileName);
    
    //-------------------------------------------------------------------------
    
    //get bitmap dimensions
    status = GetBitmapData (bmpHandler, &ByteInRow, &Pixel, &pWidth, &pHeight, NULL, NULL, NULL);
    if(status != UIENoError)
    {
        __F_voError("Failed to get bitmap dimensions" , FileName);
        __F_voFree_Resources(&bmpHandler , &outBitmap , &MyPicData);
        return(FALSE);
    }
    
    //-------------------------------------------------------------------------
    
    //memory allocation
    BitSize = pWidth * pHeight * (Pixel/8) *2;
    MyPicData = (unsigned char*) malloc(BitSize);
    if(MyPicData == NULL)
    {
        __F_voError("Failed to allocate memory" , FileName);
        __F_voFree_Resources(&bmpHandler , &outBitmap , &MyPicData);
        return(FALSE);
    }
    
    //get bitmap info + dimensions
    status = GetBitmapData (bmpHandler, &ByteInRow, &Pixel, &pWidth, &pHeight, NULL, MyPicData, NULL);
    if(status != UIENoError)
    {
        __F_voError("Failed to get bitmap info" , FileName);
        __F_voFree_Resources(&bmpHandler , &outBitmap , &MyPicData);
        return(FALSE);
    }

    //get image to a 2D-array
    int pWidthArr, pHeightArr;
    double ArrFromImage[][];
    ArrFromImage = imaqImageToArray (MyPicData, IMAQ_NO_RECT, &pWidthArr, &pHeightArr);
    if(ArrFromImage == NULL)
    {
        __F_voError("Failed to get 2D-array from image" , FileName);
        imaqDispose(ArrFromImage);
        return(FALSE);
    }
    
    
    //-------------------------------------------------------------------------
    
    //fourier transform
    //=================
    double      fftOut[pHeight][pWidth * 2];

    analysisErr = FFT2D(bits, 
                        pHeight,    //NUM_ROWS, 
                        pWidth,     //NUM_COLS, 
                        pHeight,    //NUM_ROWS,
                        pWidth,     //NUM_COLS, 
                        0, 
                        fftOut);
    
    if(analysisErr != NoAnlysErr)
    {
        __F_voError("Failed to perform fourier transform" , FileName);
        __F_voFree_Resources(&bmpHandler , &outBitmap , &MyPicData);
        return(FALSE);
    }
    
    //-------------------------------------------------------------------------
    
    //inverse fourier transform
    //=========================
    double      fftInv[pHeight][pWidth * 2];

    analysisErr = InvFFT2D(fftOut,      //void *frequencyDomainSignal, 
                           pHeight,     //ssize_t numberOfRows, 
                           pWidth,      //ssize_t numberOfColumns, 
                           0,           //int shifted, 
                           fftInv);     //void *fft);
    
    if(analysisErr != NoAnlysErr)
    {
        __F_voError("Failed to perform inverse fourier transform" , FileName);
        __F_voFree_Resources(&bmpHandler , &outBitmap , &MyPicData);
        return(FALSE);
    }
  • Also, what is the point of adding noise in the frequency domain? It’s just more difficult to do right than in the spatial domain. – Cris Luengo Jul 11 '20 at 13:27
  • like i said - my main problem is to understand the struct of the image as it saved using bitmap (with bitmap ID) - or saving it in array (like i tried). how do i access each row or each colunm? about the noise - i wanted to simulate the communication channel. if i will add the noise at the spatial domain - i will still be able to control the SNR? if so, i would be happy to learn how – ניר בנאי Jul 11 '20 at 13:56
  • and... of course I do not expect anyone to do the work for me. i have already written most of the code, but to continue I need to get the convenience of accessing the image – ניר בנאי Jul 11 '20 at 14:09
  • The question is clearer now, I’ve changed my vote. Thanks for updating it. – Cris Luengo Jul 11 '20 at 16:15
  • Computing the signal power is just as easy in the spatial domain as in the frequency domain. And it is simple to determine the variance of Gaussian noise required for a specific noise power. In the frequency domain you need to create complex-valued noise with complex-conjugate symmetry. In the spatial domain you just generate real-valued noise. Much easier! – Cris Luengo Jul 11 '20 at 16:17
  • Thanks a lot! It is very helpful. If i would change the image data using the pointer it will change my original image, wont it? Do you know how do i save the image data in array? One more little question - can i simulate the channel using 'not' gate at some bits? For example SNR of 0dB can be applied using 'not' randomally at 50% of the image? – ניר בנאי Jul 11 '20 at 16:42
  • Sorry, I don’t know about CVI. I guess you need to make a copy of the image to avoid changing the original one. If you want normally distributed, additive and independent noise, you need to generate normally distributed numbers and add them to your pixel values. Randomly changing bits is a very different type of noise. – Cris Luengo Jul 11 '20 at 17:17

0 Answers0