- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在寻找可用于分离两个相乘图像的算法或 C++/Matlab 库。下面给出了此问题的可视化示例。
图1可以是任何东西(比如比较复杂的场景)。图 2 非常简单,可以用数学方法生成。图 2 始终具有相似的形态(即下降趋势)。通过将图像 1 与图像 2 相乘(使用逐点乘法),我们得到了转换后的图像。
给定仅变换后的图像,我想估计图像 1 或图像 2。是否有可以执行此操作的算法?
这是 Matlab 代码和图像:
load('trans.mat');
imageA = imread('room.jpg');
imageB = abs(response); % loaded from MAT file
[m,n] = size(imageA);
image1 = rgb2gray( imresize(im2double(imageA), [m n]) );
image2 = imresize(im2double(imageB), [m n]);
figure; imagesc(image1); colormap gray; title('Image 1 of Room')
colorbar
figure; imagesc(image2); colormap gray; title('Image 2 of Response')
colorbar
% This is image1 and image2 multiplied together (point-by-point)
trans = image1 .* image2;
figure; imagesc(trans); colormap gray; title('Transformed Image')
colorbar
更新
有很多方法可以解决这个问题。这是我的实验结果。感谢所有回答我问题的人!
<强>1。图像的低通滤波
正如 duskwuff 所指出的,对转换后的图像采用低通滤波器会返回图像 2 的近似值。在这种情况下,低通滤波器一直是高斯滤波器。您可以看到使用低通滤波器可以识别图像中的乘法噪声。
<强>2。同态滤波
根据 EitenT 的建议,我检查了同态过滤。知道了这种图像过滤的名称后,我设法找到了一些我认为对解决类似问题有用的引用资料。
S。 P. Banks,信号处理、图像处理和模式识别。纽约:Prentice Hall,1990 年。
A. Oppenheim, R. Schafer 和 J. Stockham, T.,“乘法和卷积信号的非线性滤波”,IEEE 音频和电声学汇刊,卷。 16,没有。 3,第 437 - 466 页,1968 年 9 月。
盲图像反卷积:理论与应用。博卡拉顿:CRC 出版社,2007 年。
Blind image deconvolution这本书的第5章特别好,里面有很多同态滤波的引用。这可能是最通用的方法,适用于许多不同的应用程序。
<强>3。使用 fminsearch
按照 Serg 的建议,我将目标函数与 fminsearch
结合使用。因为我知道噪声的数学模型,所以我能够将其用作优化算法的输入。 这种方法完全是针对特定问题的,可能并不总是适用于所有情况。
这是图像 2 的重建:
这是图像 1 的重建,除以图像 2 的重建:
这是包含噪声的图像:
源代码
这是我的问题的源代码。如代码所示,这是一个非常特殊的应用程序,并不是在所有情况下都能正常工作。
N = 1001;
q = zeros(N, 1);
q(1:200) = 55;
q(201:300) = 120;
q(301:400) = 70;
q(401:600) = 40;
q(601:800) = 100;
q(801:1001) = 70;
dt = 0.0042;
fs = 1 / dt;
wSize = 101;
Glim = 20;
ginv = 0;
[R, ~, ~] = get_response(N, q, dt, wSize, Glim, ginv);
rows = wSize;
cols = N;
cut_val = 200;
figure; imagesc(abs(R)); title('Matrix output of algorithm')
colorbar
figure;
imagesc(abs(R)); title('abs(response)')
figure;
imagesc(imag(R)); title('imag(response)')
imageA = imread('room.jpg');
% images should be of the same size
[m,n] = size(R);
image1 = rgb2gray( imresize(im2double(imageA), [m n]) );
% here is the multiplication (with the image in complex space)
trans = ((image1.*1i)) .* (R(end:-1:1, :));
figure;
imagesc(abs(trans)); colormap(gray);
% take the imaginary part of the response
imagLogR = imag(log(trans));
% The beginning and end points are not usable
Mderiv = zeros(rows, cols-2);
for k = 1:rows
val = deriv_3pt(imagLogR(k,:), dt);
val(val > cut_val) = 0;
Mderiv(k,:) = val(1:end-1);
end
% This is the derivative of the imaginary part of R
% d/dtau(imag((log(R)))
% Do we need to remove spurious values from the matrix?
figure;
imagesc(abs(log(Mderiv)));
disp('Running iteration');
% Apply curve-fitting to get back the values
% by cycling over the cols
q0 = 10;
q1 = 500;
NN = cols - 2;
qout = zeros(NN, 1);
for k = 1:NN
data = Mderiv(:,k);
qout(k) = fminbnd(@(q) curve_fit_to_get_q(q, dt, rows, data),q0,q1);
end
figure; plot(q); title('q value input as vector');
ylim([0 200]); xlim([0 1001])
figure;
plot(qout); title('Reconstructed q')
ylim([0 200]); xlim([0 1001])
% make the vector the same size as the other
qout2 = [qout(1); qout; qout(end)];
% get the reconstructed response
[RR, ~, ~] = get_response(N, qout2, dt, wSize, Glim, ginv);
RR = RR(end:-1:1,:);
figure; imagesc(abs(RR)); colormap gray
title('Reconstructed Image 2')
colorbar;
% here is the reconstructed image of the room
% NOTE the division in the imagesc function
check0 = image1 .* abs(R(end:-1:1, :));
figure; imagesc(check0./abs(RR)); colormap gray
title('Reconstructed Image 1')
colorbar;
figure; imagesc(check0); colormap gray
title('Original image with noise pattern')
colorbar;
function [response, L, inte] = get_response(N, Q, dt, wSize, Glim, ginv)
fs = 1 / dt;
Npad = wSize - 1;
N1 = wSize + Npad;
N2 = floor(N1 / 2 + 1);
f = (fs/2)*linspace(0,1,N2);
omega = 2 * pi .* f';
omegah = 2 * pi * f(end);
sigma2 = exp(-(0.23*Glim + 1.63));
sign = 1;
if(ginv == 1)
sign = -1;
end
ratio = omega ./ omegah;
rs_r = zeros(N2, 1);
rs_i = zeros(N2, 1);
termr = zeros(N2, 1);
termi = zeros(N2, 1);
termr_sub1 = zeros(N2, 1);
termi_sub1 = zeros(N2, 1);
response = zeros(N2, N);
L = zeros(N2, N);
inte = zeros(N2, N);
% cycle over cols of matrix
for ti = 1:N
term0 = omega ./ (2 .* Q(ti));
gamma = 1 / (pi * Q(ti));
% calculate for the real part
if(ti == 1)
Lambda = ones(N2, 1);
termr_sub1(1) = 0;
termr_sub1(2:end) = term0(2:end) .* (ratio(2:end).^-gamma);
else
termr(1) = 0;
termr(2:end) = term0(2:end) .* (ratio(2:end).^-gamma);
rs_r = rs_r - dt.*(termr + termr_sub1);
termr_sub1 = termr;
Beta = exp( -1 .* -0.5 .* rs_r );
Lambda = (Beta + sigma2) ./ (Beta.^2 + sigma2); % vector
end
% calculate for the complex part
if(ginv == 1)
termi(1) = 0;
termi(2:end) = (ratio(2:end).^(sign .* gamma) - 1) .* omega(2:end);
else
termi = (ratio.^(sign .* gamma) - 1) .* omega;
end
rs_i = rs_i - dt.*(termi + termi_sub1);
termi_sub1 = termi;
integrand = exp( 1i .* -0.5 .* rs_i );
L(:,ti) = Lambda;
inte(:,ti) = integrand;
if(ginv == 1)
response(:,ti) = Lambda .* integrand;
else
response(:,ti) = (1 ./ Lambda) .* integrand;
end
end % ti loop
function sse = curve_fit_to_get_q(q, dt, rows, data)
% q = trial q value
% dt = timestep
% rows = number of rows
% data = actual dataset
fs = 1 / dt;
N2 = rows;
f = (fs/2)*linspace(0,1,N2); % vector for frequency along cols
omega = 2 * pi .* f';
omegah = 2 * pi * f(end);
ratio = omega ./ omegah;
gamma = 1 / (pi * q);
% calculate for the complex part
termi = ((ratio.^(gamma)) - 1) .* omega;
% for now, just reverse termi
termi = termi(end:-1:1);
%
% Do non-linear curve-fitting
% termi is a column-vector with the generated noise pattern
% data is the log-transformed image
% sse is the value that is returned to fminsearchbnd
Error_Vector = termi - data;
sse = sum(Error_Vector.^2);
function output = deriv_3pt(x, dt)
N = length(x);
N0 = N - 1;
output = zeros(N0, 1);
denom = 2 * dt;
for k = 2:N0
output(k - 1) = (x(k+1) - x(k-1)) / denom;
end
最佳答案
这将是一个困难、不可靠的过程,因为您要从根本上尝试提取已被破坏的信息(两个图像的分离)。把它完美地带回来是不可能的;您最多只能猜测。
如果第二张图片总是相对“平滑”,您可以通过对转换后的图片应用强低通滤波器来重建它(或至少是它的近似值)。有了它,您可以反转乘法,或者等效地使用互补的高通滤波器来获得第一张图像。它不会完全相同,但至少会有所不同。
关于c++ - 自动分离已相乘的两个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12028475/
int SIZE = 512; p = new BigInteger(SIZE, 15, new Random()); q = new BigInteger(SIZE, 15, new
我正在寻找一种方法来扩展以下形式的逻辑表达式(在字符串中): “(A或B)和((C和D)或E)” 在Python中生成所有正集的列表,即 ['A and C and D', 'A and E', 'B
我正在从 MySQL 数据库中提取一组数字,并尝试对它们进行一些简单的数学运算来计算要放入发票中的总价格,但 PHP 不配合。我认为这可能是类型强制问题,因此我尝试添加一些 intval 和 floa
给定一个包含多列字典的数据框,我如何将数据框中的键相加和/或相乘以获得一列 A B {"ab":1,
我有 2 个 UIImageView - 一个在底部并显示默认图像(如照片)- 在第二个 UIImageView 上您可以在其中绘制。 我想从两个图像创建一个 UIImage,并将其保存为新图像。 我
我有一项作业,并且我已经写完了前两部分,但我只是不知道如何找到最小的数字。我应该提到它在 jFrame (gui) 中。它应该看起来像这样: 假设我有一个数字列表 (10 5 8 7 4 9),我想知
我是 python 的新手,但是有没有办法将矩阵与 0 和符号相乘?例如,见下文: import sympy as sym import numpy as np teams=np.matrix([[1
让我们为变量赋值: thisIsANumberVariable % +5 #adds 5 to thisIsANumberVariable thisIsANumberVariable [1] 8 th
我正在尝试以下操作: Eigen::SparseMatrix bijection(2 * face_count, 2 * vert_count); /* initialization */ Eigen
我必须创建一个没有 * 或 / 运算符的乘法函数。我已经做了这样的方法。 for(int i=0; i < number1; i++){ result += number2; } System
让我们为变量赋值: thisIsANumberVariable % +5 #adds 5 to thisIsANumberVariable thisIsANumberVariable [1] 8 th
这个问题已经有答案了: Convert String to double in Java (14 个回答) 已关闭 9 年前。 我的代码有问题。所以我知道我不能将我所拥有的乘以字符串,但我真的不知道有
我正在尝试以下操作: Eigen::SparseMatrix bijection(2 * face_count, 2 * vert_count); /* initialization */ Eigen
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我需要将矩阵和 vector 相乘。 为了实现这一点,我编写了一个带参数的函数: float** M 尺寸的最大值:m x n。 float* V 长度为 n 的 vector 。 float* R
我正在尝试找出一个好的循环展开来将两个矩阵相乘。 例如,如果我们想要对 NxN 矩阵求和: void SumMatrix(int *M, int n, int *result) { int i,
如果我创建一个像这样的字符串 mutiples=[1,2,3,4,5] 我希望能够使用 .forEach 将它们相乘,我该怎么做?我最好的猜测是: var total=0 multiples=[1,2
我试图将 price(1-3) 标签中的数据乘以 counterValue 以显示所选每个选项的价格 到目前为止,我的代码可以将counterValue 乘以所选选项Btn(1-3) 的因子 被选中
我有两个大小相同的 3-D 数组 a 和 b np.random.seed([3,14159]) a = np.random.randint(10, size=(4, 3, 2)) b = np.ra
关闭。这个问题需要details or clarity .它目前不接受答案。 想改进这个问题吗? 通过 editing this post 添加细节并澄清问题. 关闭 4 年前。 Improve t
我是一名优秀的程序员,十分优秀!