質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

Q&A

0回答

1100閲覧

Retinex処理がされているのか定かでない

aisuryo000

総合スコア5

C

C言語は、1972年にAT&Tベル研究所の、デニス・リッチーが主体となって作成したプログラミング言語です。 B言語の後継言語として開発されたことからC言語と命名。そのため、表記法などはB言語やALGOLに近いとされています。 Cの拡張版であるC++言語とともに、現在世界中でもっとも普及されているプログラミング言語です。

Visual Studio

Microsoft Visual StudioはMicrosoftによる統合開発環境(IDE)です。多種多様なプログラミング言語に対応しています。

C++

C++はC言語をもとにしてつくられた最もよく使われるマルチパラダイムプログラミング言語の1つです。オブジェクト指向、ジェネリック、命令型など広く対応しており、多目的に使用されています。

0グッド

0クリップ

投稿2020/01/09 14:19

編集2020/01/10 02:22

Visual Stadioで画像にRetinex処理をかけ出力するコードを作成しているのですが出力される画像がRetinex処理されているとあまり思えません。(白飛び、黒つぶれなどが改善されていないため)
コントラスト補正によって明るさは変化するのですが白飛び、黒つぶれなどを改善するにはどの部分を変更すればよいでしょうか。画像中の空の白飛び部分の改善ができていない点でこの疑問になりました。よろしくお願いいたします。
コントラスト補正の部分は出力画像作成に当たり手動入力で0.58に変更しています。

入力画像
イメージ説明

出力画像
イメージ説明

#include "main.h"
int main(int argc, char **argv)
{
int x, y, c, i;
int nn;/ボケ具合を決定するm(=σ^2)/
int addr = 0;//data配列の先頭アドレスからのRGBデータの位置
int addr2 = 0;
int sigma;//σmの値

double gain = 0.2;//ゲイン係数 double *retinex;//retinex処理時格納用ポインタ double *imgbuf1;//RGBデータ計算用ポインタ double *Yc;//輝度画像用ポインタ double *gaus, *gaus2, *gaus3;//, *gaus4, *gaus5, *gaus6, *gaus7;//ガウスフィルタ用ポインタ double *IL_image;//照明輝度画像用ポインタ double max = 0; char in_imagename[20], out_imagename[20]; double **a, **il, *w; int *ip, n, pix; if (argc < 1) { fprintf(stderr, "usage : %s jpegfile\n", *argv); exit(1); } /*入力画像のファイル名と出力画像のファイル名入力*/ printf("press, Include image name... : "); scanf("%s", in_imagename); printf("press, Create image name... : "); scanf("%s", out_imagename); read_JPEG_file(in_imagename);;/*wigth height byteppにそれぞれ読み込んだ画像の値が入る*/ printf("Imput image size: width %d x height %d x color %d\n\n", image_width, image_height, image_bytepp); il = alloc_2d_double(image_height, image_width); a = alloc_2d_double(image_height, image_width); n = MAX(image_height, image_width / 2); ip = alloc_1d_int(2 + (int)sqrt(n + 0.5)); n = MAX(image_height, image_width) * 3 / 2; w = alloc_1d_double(n); ip[0] = 0; pix = image_width*image_height; /*メモリの動的確保*/ imgbuf1 = (double*)malloc(image_height*image_width*image_bytepp*sizeof(double)); Yc = (double*)malloc(image_height*image_width*sizeof(double)); IL_image = (double*)malloc(image_height*image_width*sizeof(double)); retinex = (double*)malloc(image_height*image_width*image_bytepp*sizeof(double)); gaus = (double*)malloc(image_height*image_width*sizeof(double));/*フィルタ配列の動的確保*/ gaus2 = (double*)malloc(image_height*image_width*sizeof(double)); gaus3 = (double*)malloc(image_height*image_width*sizeof(double)); /*確保した配列を0で初期化する*/ for (c = 0; c < image_bytepp; c++) { for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { addr = (y*image_width + x)*image_bytepp; imgbuf1[addr + c] = 0; retinex[addr + c] = 0; } } } /*確保配列0で初期化*/ for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { Yc[x + y*image_width] = 0; IL_image[x + y*image_width] = 0; gaus[x + y*image_width] = 0; gaus2[x + y*image_width] = 0; gaus3[x + y*image_width] = 0; } } /*読込んだdata[image_buffer]を計算用配列に挿入*/ for (c = 0; c < image_bytepp; c++) { for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { addr = (y*image_width + x)*image_bytepp; imgbuf1[addr + c] = data[addr + c]; } } } /*読込んだdataを逆ガンマとって0~1に正規化*/ for (c = 0; c < image_bytepp; c++) { for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { addr = (y*image_width + x)*image_bytepp; imgbuf1[addr + c] = pow(imgbuf1[addr + c] / 255., 2.2); } } } /*輝度画像作成*/ for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { addr = (y*image_width + x)*image_bytepp; Yc[x + y*image_width] = 0.299*imgbuf1[addr] + 0.587*imgbuf1[addr + 1] + 0.114*imgbuf1[addr + 2]; } } /*処理開始*/ t0 = clock(); /*gaussian filter 作成*/ /*sigma = 2; for (y = 0; y < image_height; y++){ for (x = 0; x < image_width; x++){ gaus[x + y * image_width] = exp(-(x*x + y*y) / (2.*sigma*sigma)); a[y][x] = Yc[x + y * image_width]; } }*/ sigma = 16; for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { gaus2[x + y * image_width] = exp(-(x*x + y*y) / (2.*sigma*sigma)); } } /*sigma =128; for (y = 0; y < image_height; y++){ for (x = 0; x < image_width; x++){ gaus3[x + y * image_width] = exp(-(x*x + y*y) / (2.*sigma*sigma)); } }*/ /*DCT処理*/ ddct2d(image_height, image_width, -1, a, NULL, ip, w); for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { il[y][x] = a[y][x] * (gaus[x + y * image_width] * 0.3 + gaus2[x + y * image_width] * 0.1 + gaus3[x + y * image_width] * 0.6); } } for (y = 0; y < image_height; y++) { il[y][0] *= 0.5; } for (x = 0; x < image_width; x++) { il[0][x] *= 0.5; } ddct2d(image_height, image_width, 1, il, NULL, ip, w); for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { il[y][x] = il[y][x] / pix; } } /*コントラスト補正*/ for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { IL_image[x + y*image_width] = 0.98*(il[y][x] - 0.5) + 0.5; } } for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { if (IL_image[x + y*image_width] > 1) IL_image[x + y*image_width] = 1; if (IL_image[x + y*image_width] < 0) IL_image[x + y*image_width] = 0; } } /*Retinex処理*/ for (y = 0; y < image_height; y++) { for (x = 0; x < image_width; x++) { for (c = 0; c < image_bytepp; c++) { addr = (y*image_width + x)*image_bytepp; if (IL_image[x + y*image_width] == 0)retinex[addr + c] = 0; else retinex[addr + c] = gain*imgbuf1[addr + c] / IL_image[x + y*image_width]; /*0~1の間以外をとらないように制限をかける*/ if (retinex[addr + c]>1) retinex[addr + c] = 1; if (retinex[addr + c] < 0) retinex[addr + c] = 0; data[addr + c] = (unsigned char)(255 * pow(retinex[addr + c], 1 / 2.2)); //(unsigned char)(255 * pow(retinex[addr + c], 1 / 2.2));; } } } printf("σm = %d Complete.\n\n", sigma); write_JPEG_file(out_imagename, OUTPUT_QUALITY); t1 = clock(); printf("%lf[s]\n\n", (t1 - t0) / 1000.0); printf("\nRetinex Processing Conmplete...\n"); printf("Generate image for %s\n\n", out_imagename); free(data); free(imgbuf1); free(Yc); free(retinex); free(gaus); free(gaus2); free(gaus3); free(IL_image); fflush(stdin); getchar(); return(0); }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

fana

2020/01/10 01:18

処理前後の画像例と,そのどこら辺を見て疑念を抱いているのか,等の情報提示が必要ではないでしょうか.
aisuryo000

2020/01/10 02:22

編集させていただきました、よろしくお願いいたします
fana

2020/01/10 02:27

かなり変化が少ないですね…(左下のアンテナみたいなのとかは明瞭になってもよいように思う) あと,なぜか微妙に拡大縮小されている?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問