# 图像处理哈哈镜

## 哈哈镜局部放大缩小图像处理算法

2019-04-26 17:31:27 IKMIC 阅读数 432

``````
protected  static Bitmap change2bitmap(Bitmap mbitmap) {
int width = mbitmap.getWidth();
int height = mbitmap.getHeight();
int pixR = 0;
int pixG = 0;
int pixB = 0;
int newR = 0;
int newG = 0;
double dis =0.0;
int newB = 0;
int buf[] =new int[width * height];
int centerX = 500;
int centerY =1100;//圆心坐标
int pixels[]=new int[width * height];
mbitmap.getPixels(buf, 0, width, 0, 0, width, height);
for (int i = 0; i < width; i++)
{
for (int j = 0; j < height; j++)
{
int arrl_color = buf[j * width + i];
pixR = red(arrl_color);
pixG = green(arrl_color);
pixB = blue(arrl_color);
newR = pixR;
newG = pixG;
newB = pixB;
int   distance =  ((centerX - i) * (centerX - i) + (centerY - j) * (centerY - j));
dis=Math.sqrt(distance);
{

int src_x1 = i - centerX;
int src_y1 = j - centerY;
src_x = src_x+ centerX;
src_y = src_y + centerY;
int src_color = buf[src_y * width + src_x];
newR = red(src_color);
newG = green(src_color);
newB = blue(src_color);

}

newR = Math.min(255, Math.max(0, newR));
newG = Math.min(255, Math.max(0, newG));
newB = Math.min(255, Math.max(0, newB));
pixels[width * j + i] = Color.argb(255, newR, newG, newB);
}
}

mbitmap = Bitmap.createBitmap(pixels, width, height, Bitmap.Config.ARGB_4444);
return mbitmap;

}

}
``````

int src_x1 = (int) ((float) (i - centerX) );
int src_y1 = (int) ((float) (j - centerY)
src_x = src_x+ centerX;
src_y = src_y + centerY;

## 图像处理的哈哈镜

2016-05-06 20:06:20 u012590570 阅读数 2885

# 图像处理的哈哈镜

## Win8 Metro(C#)数字图像处理--2.61哈哈镜效果

2015-04-22 12:36:35 Trent1985 阅读数 1591
﻿﻿

[函数名称]

哈哈镜效果函数  WriteableBitmap DistortingMirrorProcess(WriteableBitmap src, int x, int y)

[算法说明]

哈哈镜效果图像实际上是一种图像形变特效而已，对于这个特效，我们可以通过三角变换来实现。

1，对于哈哈镜效果变换，首先它有两个参数，原点坐标和特效影响因子。

对于图像中的像素点P(x,y)，假设原点坐标为XY，那么，根据三角函数变换可以得到：

当前像素P的相对坐标cX,cY:

```        /// <summary>
/// Distorting mirror process.
/// </summary>
/// <param name="src">The source image.</param>
/// <param name="x">Origin of coordinates in x direction.</param>
/// <param name="y">Origin of coordinates in y direction.</param>
/// <returns></returns>
public static WriteableBitmap DistortingMirrorProcess(WriteableBitmap src, int x, int y)////哈哈镜特效
{
if (src != null)
{
int w = src.PixelWidth;
int h = src.PixelHeight;
WriteableBitmap srcImage = new WriteableBitmap(w, h);
byte[] temp = src.PixelBuffer.ToArray();
double theta = 0;
int tX = 0;
int tY = 0;
int mapX = 0;
int mapY = 0;
int mapR=0;
for (int j = 0; j < h; j++)
{
for (int i = 0; i < w; i++)
{
tX = i - x;
tY = j - y;
theta = Math.Atan2((double)tY, (double)tX);
radius = (int)Math.Sqrt((double)(tX * tX + tY * tY));
mapX = x + (int)(mapR * Math.Cos(theta));
mapY = y + (int)(mapR * Math.Sin(theta));
temp[i * 4 + j * w * 4] = tempMask[mapX * 4 + mapY * w * 4];
temp[i * 4 + 1 + j * w * 4] = tempMask[mapX * 4 + 1 + mapY * w * 4];
temp[i * 4 + 2 + j * w * 4] = tempMask[mapX * 4 + 2 + mapY * w * 4];
}
}
Stream sTemp = srcImage.PixelBuffer.AsStream();
sTemp.Seek(0, SeekOrigin.Begin);
sTemp.Write(temp, 0, w * 4 * h);
return srcImage;
}
else
{
return null;
}
}```

[图像效果]

## 图像处理之哈哈镜的实现

2014-08-27 11:43:00 weixin_34129145 阅读数 340

处理效果对比图1

## OpenCV 图像处理 哈哈镜效果

2014-01-03 09:24:28 cbacq 阅读数 2190

```void MaxFrame(IplImage* frame)
{
uchar* old_data = (uchar*)frame->imageData;
uchar* new_data = new uchar[frame->widthStep * frame->height];

int center_X = frame->width / 2;
int center_Y = frame->height / 2;
int newX = 0;
int newY = 0;

for (int i = 0; i < frame->width; i++)
{
for (int j = 0; j < frame->height; j++)
{
int tX = i - center_X;
int tY = j - center_Y;

int distance = (int)(tX * tX + tY * tY);
{
newX = (int)((float)(tX) / 2.0);
newY = (int)((float)(tY) / 2.0);

newX = (int) (newX * (sqrt((double)distance) / real_radius));
newX = (int) (newX * (sqrt((double)distance) / real_radius));

newX = newX + center_X;
newY = newY + center_Y;

new_data[frame->widthStep * j + i * 3] = old_data[frame->widthStep * newY + newX * 3];
new_data[frame->widthStep * j + i * 3 + 1] =old_data[frame->widthStep * newY + newX * 3 + 1];
new_data[frame->widthStep * j + i * 3 + 2] =old_data[frame->widthStep * newY + newX * 3 + 2];
}
else
{
new_data[frame->widthStep * j + i * 3] =  old_data[frame->widthStep * j + i * 3];
new_data[frame->widthStep * j + i * 3 + 1] =  old_data[frame->widthStep * j + i * 3 + 1];
new_data[frame->widthStep * j + i * 3 + 2] =  old_data[frame->widthStep * j + i * 3 + 2];
}
}
}
memcpy(old_data, new_data, sizeof(uchar) * frame->widthStep * frame->height);
delete new_data;
}```

```void MinFrame(IplImage* frame)
{
uchar* old_data = (uchar*)frame->imageData;
uchar* new_data = new uchar[frame->widthStep * frame->height];

int center_X = frame->width / 2;
int center_Y = frame->height / 2;

double theta = 0;
int newX = 0;
int newY = 0;

for (int i = 0; i < frame->width; i++)
{
for (int j = 0; j < frame->height; j++)
{
int tX = i - center_X;
int tY = j - center_Y;

theta = atan2((double)tY, (double)tX);
radius = (int)sqrt((double)(tX * tX) + (double) (tY * tY));
int newR = (int)(sqrt((double)radius) * 12);
newX = center_X + (int)(newR * cos(theta));
newY = center_Y + (int)(newR * sin(theta));

if (!(newX > 0 && newX < frame->width))
{
newX = 0;
}
if (!(newY > 0 && newY < frame->height))
{
newY = 0;
}

new_data[frame->widthStep * j + i * 3] = old_data[frame->widthStep * newY + newX * 3];
new_data[frame->widthStep * j + i * 3 + 1] =old_data[frame->widthStep * newY + newX * 3 + 1];
new_data[frame->widthStep * j + i * 3 + 2] =old_data[frame->widthStep * newY + newX * 3 + 2];
}
}
memcpy(old_data, new_data, sizeof(uchar) * frame->widthStep * frame->height);
delete new_data;
}```