www.pudn.com > source.zip > ImOp.cpp
#include "gui.h"
/*********************************************************************
/* Functions of ImageOperations class
/********************************************************************/
ImageOperations::ImageOperations(wxWindow *_frame)
{
frame = _frame;
in_image = out_image = NULL;
out_image2 = out_image3 = out_image4 = NULL;
no_regions = -1; // -1 ==> num. of regions has not been specified yet!
no_regions2 = -1;
ColorVariance = NULL;
ColorMean = NULL;
global_en = 0;
iterations = 0;
Ced_Pix = 0;
}
wxImage *ImageOperations::LoadBmp(wxString bmp_name)
{
wxImage *img = new wxImage(bmp_name);
if (img->Ok()) // set new values
{
in_image = img;
height = in_image->GetHeight();
width = in_image->GetWidth();
out_image = NULL;
}
return in_image;
}
bool ImageOperations::SaveBmp(wxString bmp_name,int i)
{
if(i == 0){
return out_image->SaveFile(bmp_name, wxBITMAP_TYPE_BMP);
}
if(i == 1){
return out_image2->SaveFile(bmp_name, wxBITMAP_TYPE_BMP);
}
if(i == 2){
return out_image3->SaveFile(bmp_name, wxBITMAP_TYPE_BMP);
}
if(i == 3){
return out_image4->SaveFile(bmp_name, wxBITMAP_TYPE_BMP);
}
return 1;
}
bool ImageOperations::IsOutput()
{
if (out_image == NULL) return false;
else return true;
}
void ImageOperations::CreateOutput(int l)
{
int i, j;
unsigned char *out_data;
unsigned char *orig_data = in_image->GetData();
out_data = (unsigned char *)malloc(width*height*3*sizeof(unsigned char));
// cretae output image
for (i=0; iGetInputWindow()->SetScrollbars(10,10,(out_image->GetWidth())/10,(out_image->GetHeight())/10);
((MyFrame *)frame)->GetInputWindow()->SetBmp(out_image);
((MyFrame *)frame)->GetInputWindow()->Refresh();
((MyFrame *)frame)->GetInputWindow()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
void ImageOperations::CreateOutputG(int l)
{
int i, j;
unsigned char *out_data;
unsigned char *orig_data = in_image->GetData();
out_data = (unsigned char *)malloc(width*height*3*sizeof(unsigned char));
// cretae output image
for (i=0; iGetInputWindow()->SetScrollbars(10,10,(out_image->GetWidth())/10,(out_image->GetHeight())/10);
((MyFrame *)frame)->GetInputWindow()->SetBmp(out_image);
((MyFrame *)frame)->GetInputWindow()->Refresh();
((MyFrame *)frame)->GetInputWindow()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
void ImageOperations::CreateOutput(unsigned char *input_pic)
{
free (out_image2);
out_image2 = new wxImage(width, height, input_pic);
((MyFrame *)frame)->GetOutputWindow()->SetScrollbars(10,10,(out_image2->GetWidth())/10,(out_image2->GetHeight())/10);
((MyFrame *)frame)->GetOutputWindow()->SetBmp(out_image2);
((MyFrame *)frame)->GetOutputWindow()->Refresh();
((MyFrame *)frame)->GetOutputWindow()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
void ImageOperations::CreateOutput2(unsigned char *input_pic)
{
free (out_image3);
out_image3 = new wxImage(width, height, input_pic);
((MyFrame *)frame)->GetOutputWindow2()->SetScrollbars(10,10,(out_image3->GetWidth())/10,(out_image3->GetHeight())/10);
((MyFrame *)frame)->GetOutputWindow2()->SetBmp(out_image3);
((MyFrame *)frame)->GetOutputWindow2()->Refresh();
((MyFrame *)frame)->GetOutputWindow2()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
void ImageOperations::CreateOutput3(unsigned char *input_pic)
{
free (out_image4);
out_image4 = new wxImage(width, height, input_pic);
((MyFrame *)frame)->GetOutputWindow3()->SetScrollbars(10,10,(out_image4->GetWidth())/10,(out_image4->GetHeight())/10);
((MyFrame *)frame)->GetOutputWindow3()->SetBmp(out_image4);
((MyFrame *)frame)->GetOutputWindow3()->Refresh();
((MyFrame *)frame)->GetOutputWindow3()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
void ImageOperations::CreateOutput(wxImage input_pic)
{
free (out_image);
out_image = new wxImage(input_pic);
((MyFrame *)frame)->GetOutputWindow()->SetScrollbars(10,10,(out_image->GetWidth())/10,(out_image->GetHeight())/10);
((MyFrame *)frame)->GetOutputWindow()->SetBmp(out_image);
((MyFrame *)frame)->GetOutputWindow()->Refresh();
((MyFrame *)frame)->GetOutputWindow()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
void ImageOperations::CreateOutputIn(wxImage input_pic)
{
free (out_image);
out_image = new wxImage(input_pic);
((MyFrame *)frame)->GetInputWindow()->SetScrollbars(10,10,(out_image->GetWidth())/10,(out_image->GetHeight())/10);
((MyFrame *)frame)->GetInputWindow()->SetBmp(out_image);
((MyFrame *)frame)->GetInputWindow()->Refresh();
((MyFrame *)frame)->GetInputWindow()->Update();
frame->RefreshRect(wxRect(645, 360, 100, 100));
frame->Update();
}
fftw_real* ImageOperations::gray_to_real(gray **img, fftw_real *realim, int num_rows,
int num_cols, int real_row_length)
{
int row, col;
fftw_real *im;
im = (realim == NULL? Alloc_dvector(num_rows * real_row_length) : realim);
for (row = 0; row < num_rows; row++)
for (col = 0; col < num_cols; col++)
im[row*real_row_length + col] = (double)img[row][col];
im = real_scaling(im, im, num_rows, num_cols, real_row_length,
real_row_length);
return(im);
}
gray *ImageOperations::dim(gray **in){
gray* out;
out = (unsigned char *)malloc(width*height*3*sizeof(unsigned char));
for(int i = 0;i < width; i++ ){
for(int j = 0;j < height; j++ ){
// out[i*width*3+j*3] = in[i][j];
// out[i*width*3+j*3+1] = in[i][j];
// out[i*width*3+j*3+2] = in[i][j];
out[j*width*3+i*3] = in[i][j];
out[j*width*3+i*3+1] = in[i][j];
out[j*width*3+i*3+2] = in[i][j];
}
}
return out;
}
gray *ImageOperations::dim2(gray **in, int layer){
gray* out;
out = (unsigned char *)malloc(width*height*3*sizeof(unsigned char));
for(int i = 0;i < width; i++ ){
for(int j = 0;j < height; j++ ){
// out[i*width*3+j*3] = in[i][j];
// out[i*width*3+j*3+1] = in[i][j];
// out[i*width*3+j*3+2] = in[i][j];
if(layer == COLOR){
out[j*width*3+i*3] = in[i][j] * (255/no_color_region);
out[j*width*3+i*3+1] = in[i][j] *(255/no_color_region);
out[j*width*3+i*3+2] = in[i][j] *(255/no_color_region);
}
if(layer == TEXTURE){
out[j*width*3+i*3] = in[i][j] * (255/no_texture_region);
out[j*width*3+i*3+1] = in[i][j] *(255/no_texture_region);
out[j*width*3+i*3+2] = in[i][j] *(255/no_texture_region);
}
if(layer == COMBINED){
out[j*width*3+i*3] = in[i][j] * (255/no_combined_region);
out[j*width*3+i*3+1] = in[i][j] *(255/no_combined_region);
out[j*width*3+i*3+2] = in[i][j] *(255/no_combined_region);
}
}
}
return out;
}
void ImageOperations::SetNoRegions(int n,int m)
{
no_regions = m;
if (n == -1)
{
delete [] ColorMean;
ColorMean = NULL;
ColorVariance = NULL;
}
else
{
ColorMean = new double*[3];
DetColor = new double[n];
for(i = 0; i< 3; i++){
ColorMean[i] = new double[n];
}
ColorVariance = new double**[3];
InvColor = new double**[3];
for(i = 0; i< 3; i++){
ColorVariance[i] = new double*[3];
InvColor[i] = new double*[3];
for(int j = 0; j< 3; j++){
ColorVariance[i][j] = new double[n];
InvColor[i][j] = new double[n];
}
}
temp1 = new double*[3+1];
temp2 = new double*[3+1];
for(i = 0; i< 3+1; i++){
temp1[i] = new double[3+1];
temp2[i] = new double[3+1];
}
for(i = 0; i < n; i++){
ColorMean[0][i] = -1;
ColorMean[1][i] = -1;
ColorMean[2][i] = -1;
}
for(i = 0; i < 3; i++){
for(int j = 0; j< n; j++){
ColorVariance[0][i][j] = -1;
ColorVariance[1][i][j] = -1;
ColorVariance[2][i][j] = -1;
}
}
}
}
void ImageOperations::SetNoRegions2(int n,int m)
{
no_regions = m;
if (n == -1)
{
delete [] TextureMean;
TextureMean = NULL;
TextureVariance = NULL;
}
else
{
DetTexture = new double[n];
temp3 = new double*[no_g_feature+1];
temp4 = new double*[no_g_feature+1];
for(i = 0; i< no_g_feature+1; i++){
temp3[i] = new double[no_g_feature+1];
temp4[i] = new double[no_g_feature+1];
}
TextureMean = new double*[no_g_feature];
for(i = 0; i< no_g_feature; i++){
TextureMean[i] = new double[n];
}
TextureVariance = new double**[no_g_feature];
InvTexture = new double**[no_g_feature];
for(i = 0; i< no_g_feature; i++){
TextureVariance[i] = new double*[no_g_feature];
InvTexture[i] = new double*[no_g_feature];
for(int j = 0; j< no_g_feature; j++){
TextureVariance[i][j] = new double[n];
InvTexture[i][j] = new double[n];
}
}
for(i = 0; i < no_g_feature; i++){
for(int j = 0; j< n; j++){
TextureMean[i][j] = -1;
}
}
for(int k = 0; k < no_g_feature; k++){
for(i = 0; i < no_g_feature; i++){
for(int j = 0; j< n; j++){
TextureVariance[k][i][j] = -1;
}
}
}
}
}
void ImageOperations::Cout(int i){
if(i == 0){
CreateOutput(dim2(Color_Layer,COLOR));
}
if(i == 1){
CreateOutput(dim2(Texture_Layer,TEXTURE));
}
if(i == 2){
CreateOutput(dim2(X_Layer,COMBINED));
}
}