- don't save images by taking screenshots of the figure, unless you want the result to be arbitrarily resized and padded.
- don't save images as JPG, especially not for synthetic technical images -- especially not in MATLAB.
How to superimpose a segment image to original image?
조회 수: 1 (최근 30일)
이전 댓글 표시
segment=imread('1.1.jpg');
original=imread('1.jpg');
I using
superimpose=imfuse(segment,original);
but it cant work, how can I place the segment img with transparency on top of original image?
댓글 수: 0
답변 (1개)
DGM
2024년 10월 12일
This is what your label image looks like.
That's not useful as a label image anymore.
You can try to un-ruin it, but good luck.
% the images
BG = imread('1.jpg');
FG = imread('2.jpg');
% try to fix the fact that it's a padded screenshot
sza = size(BG,1:2); % we're lucky
p0 = [83 30];
FG = imcrop(FG,[p0 fliplr(sza)-1]);
imshow(imcomplement(FG))
% try to un-ruin everything done by JPG
FG = im2gray(FG); % get rid of unnecessary color
mk = FG < 230; % get rid of inverted background
mk = bwareaopen(mk,10); % try to get rid of artifacts
mk = ~bwareaopen(~mk,10); % try to get rid of artifacts
mk = bwmorph(mk,'open'); % try to fix broken edges
L = bwlabel(mk,4); % use 4-connectivity to avoid weak edges
% just throw together an overlay image
outpict = labeloverlay(BG,L);
imshow(outpict)
The result is still incomplete, since some of the small labeled regions are severely damaged or missing. Could it be improved? Probably, but the best way to fix a manufactured problem is to simply not create it. All this garbage could have been avoided by simply saving the original binary image or label array in a lossless format.
I know this example uses im2gray() and labeloverlay(), neither of which were available in 2015. I don't feel like playing time traveller tonight. I've posted plenty of examples that could replace im2gray(), and I believe I've done similar for the labeloverlay() composition task.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 3-D Volumetric Image Processing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!