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:
- i can use 2DFFT or 1DFFT for rows and than columns
- 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);
}