在不丢失图像细节的情况下降低目标对比度
Decrease Target Contrast without losing image details
我有一张原始图像(左侧),我想降低对象(水平形状的东西)对比度以模拟参考图像(右侧)。我已经尝试了所有平滑方法,但它们都会影响图像对比度(比如背景对比度)。有什么方法可以构建模型然后从原始图像中减去它吗?
换句话说,有没有什么办法可以给左边的图片加上不透明度来模拟右边的图片呢?已提供对象蒙版,它与原始图像大小相同。
如有任何建议,我们将不胜感激。
您通过乘以输入图像中的遮罩区域来降低对比度:
I = imread('https://i.stack.imgur.com/QML1p.png'); %I = imread('1.png'); %Read image
M = imbinarize(imread('https://i.stack.imgur.com/nBqeS.png')); %imbinarize(imread('2.png')); %Read mask, and convert to binary image.
J = I;
J(M) = J(M)*.5; %Multiply the "horizontal shape thing" by 0.5 - reducing contrast.
figure;imshow(J);
结果:
上述解决方案是设置“形状事物”的不透明度。
我试着让它更平滑一些,但结果还是很不一样。
I = imread('https://i.stack.imgur.com/QML1p.png');
%I = imread('1.png'); %Read image
M = imbinarize(imread('https://i.stack.imgur.com/nBqeS.png'));
%M = imbinarize(imread('2.png')); %Read mask, and convert to binary image.
M = imdilate(M, strel('disk', 20)); %Make mask thicker.
%Crate blurred "shape thing"
T = zeros(size(I));
T(M) = double(I(M)); %"shape thing" with some margins, and black surrounding.
T = T/255; %Change pixels range from [0, 255] to [0, 1].
T = imgaussfilt(double(T), 5); %Blur (2-D Gaussian filtering).
%Create blurred mask:
M = imgaussfilt(double(M), 20); %Blur the mask (2-D Gaussian filtering).
M = max(M, 0.5);
J = T.*M + im2double(I).*(1-M); %Weighed average.
J = imgaussfilt(J, 1);
J = im2uint8(J);
figure;imshow(J);
结果:
试着玩一下...
再试一次:
- 通过平均 J 和 0.5 来降低“形状事物”和背景之间的相对对比度
- 添加高斯噪声(因此结果更接近参考)。
代码:
I = imread('https://i.stack.imgur.com/QML1p.png');
M = imbinarize(imread('https://i.stack.imgur.com/nBqeS.png'));
M = imdilate(M, strel('disk', 20)); %Make mask thicker.
%Crate blurred "shape thing"
T = zeros(size(I));
T(M) = double(I(M)); %"shape thing" with some margins, and black surrounding.
T = T/255; %Change pixels range from [0, 255] to [0, 1].
T = imgaussfilt(double(T), 5); %Blur (2-D Gaussian filtering).
T = T*1.5; %Scale T for changing opaquely
%Create blurred mask:
M = imgaussfilt(double(M), 20); %Blur the mask (2-D Gaussian filtering).
M = max(M, 0.5);
J = T.*M + im2double(I).*(1-M); %Weighed average.
J = imgaussfilt(J, 1);
%Reduce the relative contrast between "shape thing" and background by averaging J and 0.5
J = (J + 0.5)/2;
J = min(J, 1);
%Add gaussian noise (so result be closer to reference).
J = imnoise(J, 'gaussian', 0, 0.005);
J = im2uint8(J);
figure;imshow(J);
结果:
我有一张原始图像(左侧),我想降低对象(水平形状的东西)对比度以模拟参考图像(右侧)。我已经尝试了所有平滑方法,但它们都会影响图像对比度(比如背景对比度)。有什么方法可以构建模型然后从原始图像中减去它吗?
换句话说,有没有什么办法可以给左边的图片加上不透明度来模拟右边的图片呢?已提供对象蒙版,它与原始图像大小相同。
如有任何建议,我们将不胜感激。
您通过乘以输入图像中的遮罩区域来降低对比度:
I = imread('https://i.stack.imgur.com/QML1p.png'); %I = imread('1.png'); %Read image
M = imbinarize(imread('https://i.stack.imgur.com/nBqeS.png')); %imbinarize(imread('2.png')); %Read mask, and convert to binary image.
J = I;
J(M) = J(M)*.5; %Multiply the "horizontal shape thing" by 0.5 - reducing contrast.
figure;imshow(J);
结果:
上述解决方案是设置“形状事物”的不透明度。
我试着让它更平滑一些,但结果还是很不一样。
I = imread('https://i.stack.imgur.com/QML1p.png');
%I = imread('1.png'); %Read image
M = imbinarize(imread('https://i.stack.imgur.com/nBqeS.png'));
%M = imbinarize(imread('2.png')); %Read mask, and convert to binary image.
M = imdilate(M, strel('disk', 20)); %Make mask thicker.
%Crate blurred "shape thing"
T = zeros(size(I));
T(M) = double(I(M)); %"shape thing" with some margins, and black surrounding.
T = T/255; %Change pixels range from [0, 255] to [0, 1].
T = imgaussfilt(double(T), 5); %Blur (2-D Gaussian filtering).
%Create blurred mask:
M = imgaussfilt(double(M), 20); %Blur the mask (2-D Gaussian filtering).
M = max(M, 0.5);
J = T.*M + im2double(I).*(1-M); %Weighed average.
J = imgaussfilt(J, 1);
J = im2uint8(J);
figure;imshow(J);
结果:
试着玩一下...
再试一次:
- 通过平均 J 和 0.5 来降低“形状事物”和背景之间的相对对比度
- 添加高斯噪声(因此结果更接近参考)。
代码:
I = imread('https://i.stack.imgur.com/QML1p.png');
M = imbinarize(imread('https://i.stack.imgur.com/nBqeS.png'));
M = imdilate(M, strel('disk', 20)); %Make mask thicker.
%Crate blurred "shape thing"
T = zeros(size(I));
T(M) = double(I(M)); %"shape thing" with some margins, and black surrounding.
T = T/255; %Change pixels range from [0, 255] to [0, 1].
T = imgaussfilt(double(T), 5); %Blur (2-D Gaussian filtering).
T = T*1.5; %Scale T for changing opaquely
%Create blurred mask:
M = imgaussfilt(double(M), 20); %Blur the mask (2-D Gaussian filtering).
M = max(M, 0.5);
J = T.*M + im2double(I).*(1-M); %Weighed average.
J = imgaussfilt(J, 1);
%Reduce the relative contrast between "shape thing" and background by averaging J and 0.5
J = (J + 0.5)/2;
J = min(J, 1);
%Add gaussian noise (so result be closer to reference).
J = imnoise(J, 'gaussian', 0, 0.005);
J = im2uint8(J);
figure;imshow(J);
结果: