0
は、私は現在、私は、ディザマトリックスを命じた4×4を使用して3bppイメージに24bppの画像を縮小する必要があるプロジェクトをやっています。しかし、私のディザ処理を行った後、私の画像は約1/3しか表示されません。誰かが私が間違っていることを知っていますか?順序色のディザ
出典:
#include <stdio.h>
#include <fstream>
/*24 bit per pixel - 3 bit per pixel dither*/
/*Use the 4x4 Ordered Dither Matrix:
[1 9 3 11]
[13 5 15 7]
[4 12 2 10]
[16 8 14 6]
*/
int checkColor(int a, int b);
unsigned char buf[512][512];
unsigned char out[512][512];
float ratio = 1.0/17;
int main(){
FILE *fp, *output;
int i, j, k, l;
/*dither matrix*/
unsigned int dith[4][4] = {{1, 9, 3, 11}, {13, 5, 15, 7}, {4, 12, 2, 10}, {16, 8, 14, 6}};
if((fp = fopen("LennaRGB512.data", "rb")) == NULL){
printf("error opening file\n");
}
for (i = 0; i < 512; i++) {
for (j = 0; j < 512; j++) {
buf[i][j] = fgetc(fp); /*Put data in buffer*/
}
}
i = 0;
j = 0;
int x, y;
int bd = 64;
for (k = 0; k < 512; k++){
for (l = 0; l < 512; l++){
int oldPixel = buf[k][l];
int value = (oldPixel + (ratio * dith[k%4][l%4]));
int r = ((oldPixel >> 16) & 0xff) + value;
int g = ((oldPixel >> 8) & 0xff) + value;
int b = (oldPixel & 0xff) + value;
int newPixel = 0x000000 | checkColor(r, bd) << 16 | checkColor(g, bd) << 8 | checkColor(b, bd);
out[k][l] = newPixel;
}
}
output = fopen("converted_img.data", "wb");
for (i = 0; i < 512; i++){
for (j = 0; j < 512; j++){
fputc(out[i][j], output);
}
}
fclose(output);
fclose(fp);
return 0;
}
int checkColor(int a, int b){
return a/b * b;
}
私の画像は512×512の画像である前に、しかし、ディザリングされた私の出力画像は、画像の一部のみである(512x170)
先生はわずか4 * 4組織的ディザマトリックスを使用するために私たちに語りました。また、彼らは色のディザリングについて私たちにジャックを教えてくれませんでした。代わりに、グレースケール画像で1または0でディザすることができることを示しました。私は文字通り何もしていないので、あなたの助けに感謝します。 –
方法の詳細については、https://en.wikipedia.org/wiki/Ordered_ditheringを参照してください。しかし、彼らのpsuedocodeアルゴリズムに間違いがあるので、それを使用しないでください。各rgbトリプレットを保持するために、buf配列のサイズを512x512x3にする必要があります。最初にディザリングを適用し、3bppに変換します(これにはパレットまたはカラーマップが必要です)。私はあなたの先生が求めていることを正確に知っているので、あなたの課題をそのまま記入してください。 – MarcD
ここであなたも助けてくれてありがとう –