필터 지우기
필터 지우기

how to solarize and remove background of image

조회 수: 11 (최근 30일)
Tu Nguyen
Tu Nguyen 2022년 3월 13일
댓글: DGM 2022년 3월 14일
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);

채택된 답변

DGM
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
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 CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by