#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include"Commen.h"
#include"TRGB2HSV.h"
#include "TRGB2YUV.h"
#include "ImageProcessAPI.h"
int getPixel(unsigned char *srcData, int width, int height, int stride, int x, int y, int rgba[4])
{
x = x < 0 ? 0 : (x > width - 1 ? width - 1 : x);
y = y < 0 ? 0 : (y > height - 1 ? height - 1 : y);
int ret = 0;
if(srcData == NULL)
{
printf("input image is null!");
return -1;
}
// 图像处理,获取像素RGBA
int pos = x * 4 + y * stride;
rgba[0] = srcData[pos + 2];
rgba[1] = srcData[pos + 1];
rgba[2] = srcData[pos + 0];
rgba[3] = srcData[pos + 3];
return ret;
};
int adjustHSV(unsigned char *srcData, int width, int height, int stride, float hIntensity, float sIntensity, float vIntensity)
{
int ret = 0;
if (srcData == NULL)
{
printf("input image is null!");
return -1;
}
//Process
unsigned char R, G, B;
float h = 0, s = 0, v = 0;
unsigned char* pSrc = srcData;
int offset = stride - width * 4;
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
B = pSrc[0];
G = pSrc[1];
R = pSrc[2];
RGB2HSV(R, G, B, &h, &s, &v);
h = h + hIntensity > 360 ? h + hIntensity - 360 : h + hIntensity;
s = CLIP3(s + sIntensity, 0, 1.0f);
v = CLIP3(v + vIntensity, 0, 1.0f);
HSV2RGB(h, s, v, &R, &G, &B);
pSrc[0] = B;
pSrc[1] = G;
pSrc[2] = R;
pSrc += 4;
}
pSrc += offset;
}
return ret;
};
int extractYUV(unsigned char *srcData, int width, int height, int stride, int mode)
{
int ret = 0;
if (srcData == NULL)
{
printf("input image is null!");
return -1;
}
//Process
unsigned char R, G, B;
int y = 0, u = 0, v = 0;
unsigned char* pSrc = srcData;
int offset = stride - width * 4;
switch (mode)
{
case 0://display Y image
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
B = pSrc[0];
G = pSrc[1];
R = pSrc[2];
RGB2YUV(R, G, B, &y, &u, &v);
pSrc[0] = y;
pSrc[1] = y;
pSrc[2] = y;
pSrc += 4;
}
pSrc += offset;
}
break;
case 1://display U image
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
B = pSrc[0];
G = pSrc[1];
R = pSrc[2];
RGB2YUV(R, G, B, &y, &u, &v);
pSrc[0] = (u + 122) * 255 / 244;
pSrc[1] = (u + 122) * 255 / 244;
pSrc[2] = (u + 122) * 255 / 244;
pSrc += 4;
}
pSrc += offset;
}
break;
case 2://display V image
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
B = pSrc[0];
G = pSrc[1];
R = pSrc[2];
RGB2YUV(R, G, B, &y, &u, &v);
pSrc[0] = (u + 157) * 255 / 314;
pSrc[1] = (u + 157) * 255 / 314;
pSrc[2] = (u + 157) * 255 / 314;
pSrc += 4;
}
pSrc += offset;
}
break;
default:
break;
}
return ret;
};
int gray(unsigned char *srcData, int width, int height, int stride, int mode)
{
int ret = 0;
int i, j, gray, offset;
offset = stride - width * 4;
unsigned char* pSrc = srcData;
switch (mode)
{
case 0://mean gray method
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
gray = (pSrc[0] + pSrc[1] + pSrc[2]) / 3;
pSrc[0] = gray;
pSrc[1] = gray;
pSrc[2] = gray;
pSrc += 4;
}
pSrc += offset;
}
break;
case 1://classic gray method
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
gray = (299 * pSrc[2] + 587 * pSrc[1] + 114 * pSrc[0]) / 1000;
pSrc[0] = gray;
pSrc[1] = gray;
pSrc[2] = gray;
pSrc += 4;
}
pSrc += offset;
}
break;
case 2://photoshop gray method
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
gray = (MAX2(pSrc[0], MAX2(pSrc[1], pSrc[2])) + MIN2(pSrc[0], MIN2(pSrc[1], pSrc[2]))) / 2;
pSrc[0] = gray;
pSrc[1] = gray;
pSrc[2] = gray;
pSrc += 4;
}
pSrc += offset;
}
break;
default:
break;
}
return ret;
};
int threshold(unsigned char *srcData, int width, int height, int stride, int T)
{
int ret = 0;
int i, j, gray, offset;
offset = stride - width * 4;
unsigned char* pSrc = srcData;
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
gray = (pSrc[0] + pSrc[1] + pSrc[2]) / 3;
gray = gray < T ? 0 : 255;
pSrc[0] = gray;
pSrc[1] = gray;
pSrc[2] = gray;
pSrc += 4;
}
pSrc += offset;
}
return ret;
};
int histagram(unsigned char *srcData, int width, int height, int stride, int hist[256], int mode)
{
int ret = 0;
int i, j, gray, offset;
offset = stride - width * 4;
unsigned char* pSrc = srcData;
switch (mode)
{
case 0://Gray histagram
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
gray = (pSrc[0] + pSrc[1] + pSrc[2]) / 3;
hist[gray]++;
pSrc += 4;
}
pSrc += offset;
}
break;
case 1://Red histagram
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
hist[pSrc[2]]++;
pSrc += 4;
}
pSrc += offset;
}
break;
case 2://Green histagram
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
hist[pSrc[1]]++;
pSrc += 4;
}
pSrc += offset;
}
break;
case 3://Blue histagram
for (j = 0; j < height; j++)
{
for (i = 0; i < width; i++)
{
hist[pSrc[0]]++;
pSrc += 4;
}
pSrc += offset;
}
break;
default:
break;
}
return ret;
};
int brightContrast(unsigned char *srcData, int width, int height, int stride, int bright, int contrast)
{
int ret = 0;
bright = CLIP3(bright, -100, 100);
contrast = CLIP3(contrast, -100, 100);
//compute average light of image
int Average = 0;
int offset = stride - width * 4;
unsigned char* pSrc = srcData;
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
Average += (299 * pSrc[2] + 587 * pSrc[1] + 114 * pSrc[0]) / 1000;
pSrc += 4;
}
pSrc += offset;
}
Average = Average / (width * height);
pSrc = srcData;
unsigned char BC_MAP[256];
int temp = 0;
for (int i = 0; i < 256; i++)
{
int temp = contrast > 0 ? CLIP3(i + bright, 0, 255) : i;
if (contrast > 0)
{
temp = CLIP3(i + bright, 0, 255);
temp = CLIP3(Average + (temp - Average) * (1.0f / (1.0f - contrast / 100.0f)), 0, 255);
}
else
{
temp = i;
temp = CLIP3(Average + (temp - Average) * (1.0f + contrast / 100.0f), 0, 255);
temp = CLIP3(temp + bright, 0, 255);
}
BC_MAP[i] = temp;
}
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
pSrc[0] = BC_MAP[pSrc[0]];
pSrc[1] = BC_MAP[pSrc[1]];
pSrc[2] = BC_MAP[pSrc[2]];
pSrc += 4;
}
pSrc += offset;
}
return ret;
};
int saturationAdjust(unsigned char *srcData, int width, int height, int stride, int saturation)
{
int ret = 0;
if (saturation == 0)
return ret;
unsigned char* pSrc = srcData;
int r, g, b, rgbMin, rgbMax;
saturation = CLIP3(saturation, -100, 100);
int k = saturation / 100.0f * 128;
int alpha = 0;
int offset = stride - width * 4;
for (int j = 0; j < height; j++)
{
for (int i = 0; i < width; i++)
{
r = pSrc[2];
g = pSrc[1];
b = pSrc[0];
rgbMin = MIN2(MIN2(r, g), b);
rgbMax = MAX2(MAX2(r, g), b);
int delta = (rgbMax - rgbMin);
int value = (rgbMax + rgbMin);
if (delta == 0)
{
pSrc += 4;
continue;
}
int L = value >> 1;
int S = L < 128 ? (delta << 7) / value : (delta << 7) / (510 - value);
if (k >= 0)
{
alpha = k + S >= 128 ? S : 128 - k;
alpha = 128 * 128 / alpha - 128;
}
else
alpha = k;
r = r + ((r - L) * alpha >> 7);
g = g + ((g - L) * alpha >> 7);
b = b + ((b - L) * alpha >> 7);
pSrc[0] = CLIP3(b, 0, 255);
pSrc[1] = CLIP3(g, 0, 255);
pSrc[2] = CLIP3(r, 0, 255);
pSrc += 4;
mickey0380
- 粉丝: 2291
- 资源: 98
最新资源
- 检测机项目四工位转盘LABVIEW上位机与西门子PLC通讯操作手册及数据保存至EXCEL指南,检测机项目,四工位转盘 上位机用LABVIEW做的,工控机有2个串口和仪表VISA通讯读取保存数据到EX
- kde-l10n-Irish-4.10.5-2.el7.x64-86.rpm.tar.gz
- 最新电动汽车方案:含代码、原理图与PCB,新能源汽车从业者快速上手宝典,最新电动汽车方案,包含代码,原理图,pcb 新能源汽车从业者的好帮手,快速上手 ,核心关键词:最新电动汽车方案; 代码; 原
- kde-l10n-Italian-4.10.5-2.el7.x64-86.rpm.tar.gz
- kde-l10n-Japanese-4.10.5-2.el7.x64-86.rpm.tar.gz
- 基于FPGA自适应STC算法的可逆图像隐写技术-用于隐秘通信与信息安全传输,基于FPGA的图像隐写可逆信息隐藏 隐秘通信 加密 STC算法 信息安全MATLAB WOW HUGO 本设计利用Veri
- kde-l10n-Kazakh-4.10.5-2.el7.x64-86.rpm.tar.gz
- 三相整流仿真与单相整流仿真中的双闭环PI控制策略及SVPWM与PLL锁相环技术实现电压稳定在700V研究,三相整流仿真,电压外环电流内环双闭环pi控制,svpwm,pll锁相环,整流电压稳定在700v
- kde-l10n-Khmer-4.10.5-2.el7.x64-86.rpm.tar.gz
- kde-l10n-Korean-4.10.5-2.el7.x64-86.rpm.tar.gz
- 基于S7-300 PLC与Wincc组态的手控分拣系统方案与图纸集(附梯形图、接线图、IO分配与组态画面),基于S7-300 PLC和Wincc组态机械手分拣控制系统 带解释的梯形图程序,接线图原理图
- Java毕设项目:基于springboot+maven+mysql实现的时装购物系统服装商城【含源码+数据库+开题报告+答辩PPT+毕业论文】
- kde-l10n-Latvian-4.10.5-2.el7.x64-86.rpm.tar.gz
- 基于S7-300 PLC的滚珠自动分拣控制系统设计:梯形图程序详解与IO分配组态展示,基于S7-300 PLC的滚珠自动分拣控制系统设计直径物分拣 带解释的梯形图程序,接线图原理图图纸,io分配,组态
- kde-l10n-Lithuanian-4.10.5-2.el7.x64-86.rpm.tar.gz
- 海鸥算法SOA优化随机森林RF的预测效果对比:MSE及论文评价指标分析,算法编写简洁附带注释,数据可替换应用,利用海鸥算法SOA优化随机森林RF,然后和没有优化的原始RF进行预测效果的对比,利用预测集
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈