how to solarize and remove background of image
3 次查看(过去 30 天)
显示 更早的评论
Hi all, I do my HW assignment, I did the solarize but how can I remove the background to look like the answer image?
I3=imread('rose.png');
figure (3)
solar = uint8(255-I3);
imshow(solar);
mask2 = I3< 64;
output2 = uint8(double(solar).*(~mask2));
figure (4)
imshow(output2);
0 个评论
采纳的回答
DGM
2022-3-13
编辑:DGM
2022-3-14
Two things:
The thing you're doing here
%solar = uint8(255-I3);
is not solarization. This is just the additive inverse or complement of the source image. If you look closely at the example result, the behavior is dissimilar.
Also, the example result does not appear to have any mask applied to it at all. The background content is still there. I have a feeling that the only reason you think you need a mask is because you're doing inversion instead of solarization.
While the example image doesn't look like what you might get from some solarize filters, it can be replicated. I'm sure that nothing needs to be specific here, so I'm just going to contrive a filter based on a general assumption of behavior and desired aesthetics. What your example shows is a filter wherein the intensity response is inverted only toward the top end. Something like this:
inpict = linspace(0,1,100);
ks = 4; % shape parameter
kinv = 1; % base inversion depth [0 1]
os = 0; % base black offset
solar = ((1-os)*inpict + os).*(1 - kinv*inpict.^ks); % do tone inversion
avg0 = mean(inpict,'all'); % mean value of original image
avgs = mean(solar,'all'); % mean value of filtered image
solar = solar*avg0/avgs; % rescale to have the same mean value
h1 = plot(inpict,inpict); hold on
h2 = plot(inpict,solar);
legend([h1 h2], {'original','solarized'},'location','northwest');
Note that the filter curve will raise the midtones. This is due to the rescaling done on the last line. If that's undesired, simply don't rescale, but understand that the image will be generally dark. You can adjust the parameters to suit your expectations.
This can be applied to the image just the same:
inpict = imread('rose.png');
inpict = im2double(inpict);
ks = 4; % shape parameter
kinv = 1; % base inversion depth [0 1]
os = 0; % base offset
solar = (inpict + os).*(1 - kinv*inpict.^ks); % do tone inversion
avg0 = mean(inpict,'all'); % mean value of original image
avgs = mean(solar,'all'); % mean value of filtered image
solar = solar*avg0/avgs; % rescale to have the same mean value
figure
imshow(solar);
Note that there is no need for masking to suppress the background.
1 个评论
DGM
2022-3-14
I shoud note that If you were taught to do solarization by using the complement of the image, then this might be what you're after. It's a much more crude version than above, but it's something. The transfer function is not smooth, and it is symmetric. In this example, I'm not doing the mean-correction step, so the result is much darker overall.
inpict = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/925694/rose.png');
invpict = imcomplement(inpict);
outpict = min(inpict,invpict);
imshow(outpict)
Considering the banding and location of the peaks, this is probably the technique used to create the example image.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!