Reduce loss of quality when using imfill and imfuse

조회 수: 3 (최근 30일)
giannit
giannit 2020년 5월 6일
댓글: Image Analyst 2020년 5월 22일
I have to fill some regions of a black and white map, whose regions are black and are delimited by white borders.
This is the code
fill_regions = [ 128 58
280 80
335 292
430 430
470 475
525 525
550 655
680 610
770 380
785 480];
I = imread('https://i.imgur.com/4kWRWDV.png'); % black italy with white borders
BW = imbinarize(I,.1); % turn I into a black-white image...I had to use .1 threshold to prevent the filling of multiple adiacent regions
T = imread('https://i.imgur.com/1QY6Qw0.png'); % transparent italy, has only the borders
for i = 1:size(fill_regions,1)
BW = imfill(BW,fill_regions(i,:));
end
imshow( imfuse(BW,T,'diff') ); % add the erased borders to BW
saveas(gcf, 'test.png')
and here is a comparison between original image (left) and filled one (right)
as you can see, the filled image has poor quality (but also the original image has not the same quality as the source image...why this happens?).
Is there a way to preserve the same quality as the source image or, at least, to reduce the loss of quality?
  댓글 수: 2
darova
darova 2020년 5월 21일
I saved your boundary image, it's poor quality. Look
You don't need for loop in this case, just imfill
I1 = imfill(BW,fill_regions);
giannit
giannit 2020년 5월 21일
thank you, it works without the for loop. yes the original image is not high quality, but matlab seems to worsen it even more (borders are cut in some parts)

댓글을 달려면 로그인하십시오.

채택된 답변

giannit
giannit 2020년 5월 21일
편집: giannit 2020년 5월 22일
By placing the following command right before the saveas one
set(gcf, 'Position', get(0, 'Screensize'))
the size of the output image is increased, in my case from 853x827 to 2134x1103, and the quality of the image is increased too. However, since my screen size is 1366x768, I don't know why the size is set to 2134x1103.
EDIT
another option is to use the export_fig toolbox
export_fig test.png -m2
where -m2 produces an image double the size (in pixels) of the on screen figure

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by