📄 imagemagick.cpp
字号:
return temp;
}
Matrix<unsigned char> BlurImage(Matrix<unsigned char> &Image, double supportRadius, double sigma)
{
MatrixList<unsigned char> temp(Image);
MatrixList<unsigned char> temp2 = BlurImage(temp,supportRadius,sigma);
return temp2[0];
}
MatrixList<unsigned char> BorderImage(MatrixList<unsigned char> &Image, CimplColor borderColor, int borderWidth, int borderHeight)
{
char *map;
PixelWand *pw = NewPixelWand();
if(Image.Planes() == 1)
{
map = "I";
PixelSetRed(pw, borderColor.Intensity/255.0);
PixelSetGreen(pw, borderColor.Intensity/255.0);
PixelSetBlue(pw, borderColor.Intensity/255.0);
}
else if(Image.Planes() == 3)
{
map = "RGB";
PixelSetRed(pw, borderColor.Red/255.0);
PixelSetGreen(pw, borderColor.Green/255.0);
PixelSetBlue(pw, borderColor.Blue/255.0);
}
else if(Image.Planes() == 4)
{
map = "RGBA";
PixelSetRed(pw, borderColor.Red/255.0);
PixelSetGreen(pw, borderColor.Green/255.0);
PixelSetBlue(pw, borderColor.Blue/255.0);
PixelSetAlpha(pw, borderColor.Alpha/255.0);
}
else
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("MatrixList should consist either 1 (gray scale), 3 (RGB) or 4 (RGBA) planes!");
}
MagickBooleanType status;
MagickWand *magick_wand;
magick_wand = NewMagickWand();
int arrayLength = Image.Rows()*Image.Columns()*Image.Planes();
unsigned char *pixels = new (std::nothrow) unsigned char[arrayLength]; Utility::CheckPointer(pixels); int z=0; for(int i=0; i<Image.Rows(); i++) { for(int j=0; j<Image.Columns(); j++) { for(int k=0; k<Image.Planes(); k++) { pixels[z] = Image[k].ElemNC(i,j); z++; } } }
status = MagickConstituteImage(magick_wand, Image.Columns(), Image.Rows(), map, CharPixel, pixels);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
status = MagickBorderImage(magick_wand, pw, borderWidth, borderHeight); pw = DestroyPixelWand(pw); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
} int hei = (int)MagickGetImageHeight(magick_wand); int wid = (int)MagickGetImageWidth(magick_wand); delete [] pixels; pixels = new (std::nothrow) unsigned char[hei*wid*Image.Planes()]; Utility::CheckPointer(pixels);
status = MagickGetImagePixels( magick_wand, 0, 0, wid, hei, map, CharPixel, pixels ); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
MatrixList<unsigned char> temp(Image.Planes(), hei, wid);
z=0; for(int i=0; i<temp.Rows(); i++) { for(int j=0; j<temp.Columns(); j++) { for(int k=0; k<temp.Planes(); k++) { temp[k].ElemNC(i,j) = pixels[z]; z++; } } }
delete [] pixels; magick_wand = DestroyMagickWand(magick_wand);
return temp;
}
Matrix<unsigned char> BorderImage(Matrix<unsigned char> &Image, CimplColor borderColor, int borderWidth, int borderHeight)
{
MatrixList<unsigned char> temp(Image);
MatrixList<unsigned char> temp2 = BorderImage(temp,borderColor,borderWidth,borderHeight);
return temp2[0];
}
MatrixList<unsigned char> CharcoalImage(MatrixList<unsigned char> &Image, double supportRadius, double sigma)
{
char *map;
if(Image.Planes() == 1)
{
map = "I";
}
else if(Image.Planes() == 3)
{
map = "RGB";
}
else if(Image.Planes() == 4)
{
map = "RGBA";
}
else
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("MatrixList should consist either 1 (gray scale), 3 (RGB) or 4 (RGBA) planes!");
}
MagickBooleanType status;
MagickWand *magick_wand;
magick_wand = NewMagickWand();
int arrayLength = Image.Rows()*Image.Columns()*Image.Planes();
unsigned char *pixels = new (std::nothrow) unsigned char[arrayLength]; Utility::CheckPointer(pixels); int z=0; for(int i=0; i<Image.Rows(); i++) { for(int j=0; j<Image.Columns(); j++) { for(int k=0; k<Image.Planes(); k++) { pixels[z] = Image[k].ElemNC(i,j); z++; } } }
status = MagickConstituteImage(magick_wand, Image.Columns(), Image.Rows(), map, CharPixel, pixels);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
status = MagickCharcoalImage(magick_wand, supportRadius, sigma); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
status = MagickGetImagePixels( magick_wand, 0, 0, Image.Columns(), Image.Rows(), map, CharPixel, pixels ); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
MatrixList<unsigned char> temp(Image.Planes(), Image.Rows(), Image.Columns());
z=0; for(int i=0; i<temp.Rows(); i++) { for(int j=0; j<temp.Columns(); j++) { for(int k=0; k<temp.Planes(); k++) { temp[k].ElemNC(i,j) = pixels[z]; z++; } } }
delete [] pixels; magick_wand = DestroyMagickWand(magick_wand);
return temp;
}
Matrix<unsigned char> CharcoalImage(Matrix<unsigned char> &Image, double supportRadius, double sigma)
{
MatrixList<unsigned char> temp(Image);
MatrixList<unsigned char> temp2 = CharcoalImage(temp,supportRadius,sigma);
return temp2[0];
}
MatrixList<unsigned char> ChopImage(MatrixList<unsigned char> &Image, int offsetX, int offsetY, int chopWidth, int chopHeight)
{
char *map;
if(Image.Planes() == 1)
{
map = "I";
}
else if(Image.Planes() == 3)
{
map = "RGB";
}
else if(Image.Planes() == 4)
{
map = "RGBA";
}
else
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("MatrixList should consist either 1 (gray scale), 3 (RGB) or 4 (RGBA) planes!");
}
MagickBooleanType status;
MagickWand *magick_wand;
magick_wand = NewMagickWand();
int arrayLength = Image.Rows()*Image.Columns()*Image.Planes();
unsigned char *pixels = new (std::nothrow) unsigned char[arrayLength]; Utility::CheckPointer(pixels); int z=0; for(int i=0; i<Image.Rows(); i++) { for(int j=0; j<Image.Columns(); j++) { for(int k=0; k<Image.Planes(); k++) { pixels[z] = Image[k].ElemNC(i,j); z++; } } }
status = MagickConstituteImage(magick_wand, Image.Columns(), Image.Rows(), map, CharPixel, pixels);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
status = MagickChopImage(magick_wand, chopWidth, chopHeight, offsetX, offsetY); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
int hei = (int)MagickGetImageHeight(magick_wand); int wid = (int)MagickGetImageWidth(magick_wand);
status = MagickGetImagePixels( magick_wand, 0, 0, wid, hei, map, CharPixel, pixels ); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
MatrixList<unsigned char> temp(Image.Planes(), hei, wid);
z=0; for(int i=0; i<temp.Rows(); i++) { for(int j=0; j<temp.Columns(); j++) { for(int k=0; k<temp.Planes(); k++) { temp[k].ElemNC(i,j) = pixels[z]; z++; } } }
delete [] pixels; magick_wand = DestroyMagickWand(magick_wand);
return temp;
}
Matrix<unsigned char> ChopImage(Matrix<unsigned char> &Image, int offsetX, int offsetY, int chopWidth, int chopHeight)
{
MatrixList<unsigned char> temp(Image);
MatrixList<unsigned char> temp2 = ChopImage(temp,offsetX,offsetY,chopWidth,chopHeight);
return temp2[0];
}
MatrixList<unsigned char> CropImage(MatrixList<unsigned char> &Image, int offsetX, int offsetY, int cropWidth, int cropHeight)
{
char *map;
if(Image.Planes() == 1)
{
map = "I";
}
else if(Image.Planes() == 3)
{
map = "RGB";
}
else if(Image.Planes() == 4)
{
map = "RGBA";
}
else
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("MatrixList should consist either 1 (gray scale), 3 (RGB) or 4 (RGBA) planes!");
}
MagickBooleanType status;
MagickWand *magick_wand;
magick_wand = NewMagickWand();
int arrayLength = Image.Rows()*Image.Columns()*Image.Planes();
unsigned char *pixels = new (std::nothrow) unsigned char[arrayLength]; Utility::CheckPointer(pixels); int z=0; for(int i=0; i<Image.Rows(); i++) { for(int j=0; j<Image.Columns(); j++) { for(int k=0; k<Image.Planes(); k++) { pixels[z] = Image[k].ElemNC(i,j); z++; } } }
status = MagickConstituteImage(magick_wand, Image.Columns(), Image.Rows(), map, CharPixel, pixels);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
status = MagickCropImage(magick_wand, cropWidth, cropHeight, offsetX, offsetY);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
int hei = (int)MagickGetImageHeight(magick_wand); int wid = (int)MagickGetImageWidth(magick_wand);
status = MagickGetImagePixels( magick_wand, 0, 0, wid, hei, map, CharPixel, pixels ); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
MatrixList<unsigned char> temp(Image.Planes(), hei, wid);
z=0; for(int i=0; i<temp.Rows(); i++) { for(int j=0; j<temp.Columns(); j++) { for(int k=0; k<temp.Planes(); k++) { temp[k].ElemNC(i,j) = pixels[z]; z++; } } }
delete [] pixels; magick_wand = DestroyMagickWand(magick_wand);
return temp;
}
Matrix<unsigned char> CropImage(Matrix<unsigned char> &Image, int offsetX, int offsetY, int cropWidth, int cropHeight)
{
MatrixList<unsigned char> temp(Image);
MatrixList<unsigned char> temp2 = CropImage(temp,offsetX,offsetY,cropWidth,cropHeight);
return temp2[0];
}
MatrixList<unsigned char> MagnifyImage(MatrixList<unsigned char> &Image)
{
char *map;
if(Image.Planes() == 1)
{
map = "I";
}
else if(Image.Planes() == 3)
{
map = "RGB";
}
else if(Image.Planes() == 4)
{
map = "RGBA";
}
else
{
cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
Utility::RunTimeError("MatrixList should consist either 1 (gray scale), 3 (RGB) or 4 (RGBA) planes!");
}
MagickBooleanType status;
MagickWand *magick_wand;
magick_wand = NewMagickWand();
int arrayLength = Image.Rows()*Image.Columns()*Image.Planes();
unsigned char *pixels = new (std::nothrow) unsigned char[arrayLength]; Utility::CheckPointer(pixels); int z=0; for(int i=0; i<Image.Rows(); i++) { for(int j=0; j<Image.Columns(); j++) { for(int k=0; k<Image.Planes(); k++) { pixels[z] = Image[k].ElemNC(i,j); z++; } } }
status = MagickConstituteImage(magick_wand, Image.Columns(), Image.Rows(), map, CharPixel, pixels);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
status = MagickMagnifyImage(magick_wand);
if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
int hei = (int)MagickGetImageHeight(magick_wand); int wid = (int)MagickGetImageWidth(magick_wand); delete [] pixels; pixels = new (std::nothrow) unsigned char[hei*wid*Image.Planes()]; Utility::CheckPointer(pixels);
status = MagickGetImagePixels( magick_wand, 0, 0, wid, hei, map, CharPixel, pixels ); if (status == MagickFalse)
{
ThrowWandException(magick_wand);
}
MatrixList<unsigned char> temp(Image.Planes(), hei, wid);
z=0; for(int i=0; i<temp.Rows(); i++) { for(int j=0; j<temp.Columns(); j++) { for(int k=0; k<temp.Planes(); k++) { temp[k].ElemNC(i,j) = pixels[z]; z++; } } }
delete [] pixels; magick_wand = DestroyMagickWand(magick_wand);
return temp;
}
Matrix<unsigned char> MagnifyImage(Matrix<unsigned char> &Image)
{
MatrixList<unsigned char> temp(Image);
MatrixList<unsigned char> temp2 = MagnifyImage(temp);
return temp2[0];
}
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -