cccccccccc

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define IMG_WIDTH 1440 // Example image width
#define IMG_HEIGHT 1440 // Example image height
#define CHANNELS 1.5 // RGB三个通道

void read_image(unsigned char* image, int width, int height) {

FILE* input_file = fopen("E:\\Projects\\matlab\\yuv420.yuv", "rb");
if (input_file == NULL) {
    fprintf(stderr, "Error opening input file.\n");
    return;
}
fread(image, sizeof(unsigned char), width * height * CHANNELS, input_file);
fclose(input_file);

}

// Function to write image (placeholder, need to replace with actual image saving code)
void write_image(unsigned char* image, int width, int height) {
FILE* output_file = fopen(“E:\Projects\vs2022\masaic\mosaic_image.yuv”, “wb”);
if (output_file == NULL) {
fprintf(stderr, “Error opening output file.\n”);
return;
}
fwrite(image, sizeof(unsigned char), width * height * CHANNELS, output_file);
fclose(output_file);
}

int main() {

// Read the image
int width = IMG_WIDTH, height = IMG_HEIGHT;
unsigned char* image = (unsigned char*)malloc(width * height * CHANNELS);
read_image(image, width, height);

// Define face region coordinates (example)
int face_x = 527;
int face_y = 551;
int face_width = 500;
int face_height = 500;

// Define mosaic strength
int mosaic_strength = 10;

// y
for (int i = face_x; i < face_x + face_width; ++i) {
    for (int j = face_y; j < face_y + face_height; ++j) {
        image[j * width + i] = image[(j - j % mosaic_strength) * width + (i - i % mosaic_strength)];
    }
}
// u
for (int i = face_x / 2; i < (face_x + face_width) / 2; i++) {
    for (int j = face_y / 2; j < (face_y + face_height)/2; j++) {
        image[(j * width/2 + i) + width * height] = image[(j - j % mosaic_strength) * width/2 + (i - i % mosaic_strength) + width * height];
    }
}
// v
for (int i = face_x / 2; i < (face_x + face_width) / 2; i++) {
    for (int j = face_y / 2; j < (face_y + face_height) / 2; j++) {
        image[(j * width / 2 + i) + width * height * 5 / 4] = image[(j - j % mosaic_strength) * width/2 + (i - i % mosaic_strength) + width * height * 5 / 4];
    }
}

// Save the processed image
write_image(image, width, height);

// Free the image memory
free(image);

return 0;

}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值