diff --git a/Images/check.png b/Images/check.png deleted file mode 100644 index 0eff3f2fa9060b48bede2477bb0ee2058e2021c7..0000000000000000000000000000000000000000 Binary files a/Images/check.png and /dev/null differ diff --git a/Images/input.png b/Images/input.png index 2d49fadc9698d4e4324ffdd9ff12ced795c8e78f..1d837b29aeeb29116182669fc174e55ef71c13aa 100644 Binary files a/Images/input.png and b/Images/input.png differ diff --git a/Images/result.png b/Images/result.png deleted file mode 100644 index 6fd0a4ea2ea9c74cfc97796dd287b75e6381c36d..0000000000000000000000000000000000000000 Binary files a/Images/result.png and /dev/null differ diff --git a/SingleImageFourierTransform.cpp b/SingleImageFourierTransform.cpp index 5e72378873a62a83405202dda024288dd6ce5174..5b73aa7bc0885d04ffb3d2d380aabd3e85b57abf 100644 --- a/SingleImageFourierTransform.cpp +++ b/SingleImageFourierTransform.cpp @@ -70,7 +70,7 @@ int main() int phase_ERR = 0; long phase_width; long phase_height; - unsigned char* phase_data = readpng("Images/input.png", &phase_ERR, &phase_width, &phase_height); + unsigned char* phase_data = readpng("Images/input_phase.png", &phase_ERR, &phase_width, &phase_height); if (!phase_data) { bAmplitudeWithPhase = false; @@ -102,42 +102,109 @@ int main() } fftw_execute(forward_plan); + + unsigned char* result_data = new unsigned char[image_length]; + for (long i = 0; i < image_length; i++) + { + result_data[i] = own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length; + } + + writepng("Images/check_before.png", result_data, image_width, image_height); - //find maximum - double max = 0; for (long i = 0; i < image_length; i++) { - if (max < own_abs_2(signal_t[i]) / image_length && i != 0) - max = own_abs_2(signal_t[i]) / image_length; + result_data[i] = d2uc_converter(own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length); } + + writepng("Images/check_before_scaled.png", result_data, image_width, image_height); - unsigned char* result_data = new unsigned char[image_length]; + // --------------------------- LOWPASS + for (long i = 0; i < image_length; i++) + { + int x = i % image_width - image_width / 2; + int y = i / image_width - image_height / 2; + if (x * x + y * y > image_height * image_height / 400 && !(x == 0 && y == 0)) + { + signal_t[image_switch_index(i, image_width, image_height)][0] = 0; + signal_t[image_switch_index(i, image_width, image_height)][1] = 0; + } + } + for (long i = 0; i < image_length; i++) { - //result_data[i] = own_abs_2(signal_t[image_switch_index(i, image_width, image_height)])/image_length*255/max; - //result_data[i] = d2uc_converter(own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length); result_data[i] = own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length; - if (result_data[i] > 0 && false) - printf("%d at %d, %d\n", result_data[i], i%image_width, i / image_width); } - - writepng("Images/result.png", result_data, image_width, image_height); - + + writepng("Images/check_lowpass.png", result_data, image_width, image_height); + for (long i = 0; i < image_length; i++) { - own_polar_to_kart(signal_t[image_switch_index(i, image_width, image_height)], sqrt(result_data[i]), own_arg(signal_t[i])); + result_data[i] = d2uc_converter(own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length); } + + writepng("Images/check_lowpass_scaled.png", result_data, image_width, image_height); fftw_execute(backward_plan); for (long i = 0; i < image_length; i++) { - result_data[i] = d2uc_converter(own_abs_2(signal_s[i])/image_length); + result_data[i] = d2uc_converter(own_abs_2(signal_s[i])/image_length/image_length); + } + + writepng("Images/result_lowpass.png", result_data, image_width, image_height); + + // ----------------------------- HIGHPASS + for (long i = 0; i < image_length; i++) + { + signal_s[i][0] = sqrt(image_data[i]); + if (bAmplitudeWithPhase) + { + signal_s[i][1] = (double)phase_data[i] * 2 * M_PI / 256; + } + else + { + signal_s[i][1] = 0; + } + } + fftw_execute(forward_plan); + + for (long i = 0; i < image_length; i++) + { + int x = i % image_width - image_width / 2; + int y = i / image_width - image_height / 2; + if (x * x + y * y <= image_height * image_height / 400 && !(x == 0 && y == 0)) + { + signal_t[image_switch_index(i, image_width, image_height)][0] = 0; + signal_t[image_switch_index(i, image_width, image_height)][1] = 0; + } + } + + for (long i = 0; i < image_length; i++) + { + result_data[i] = own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length; + } + + writepng("Images/check_highpass.png", result_data, image_width, image_height); + + for (long i = 0; i < image_length; i++) + { + result_data[i] = d2uc_converter(own_abs_2(signal_t[image_switch_index(i, image_width, image_height)]) / image_length); + } + + writepng("Images/check_highpass_scaled.png", result_data, image_width, image_height); + + fftw_execute(backward_plan); + + for (long i = 0; i < image_length; i++) + { + result_data[i] = d2uc_converter(own_abs_2(signal_s[i]) / image_length / image_length); } - writepng("Images/check.png", result_data, image_width, image_height); + writepng("Images/result_highpass.png", result_data, image_width, image_height); - //delete[] result_data; + delete[] result_data; + free(image_data); + free(phase_data); delete[] signal_s; delete[] signal_t; return 0;