How do I repair noisy picture and invert the bw color?
조회 수: 6(최근 30일)
DGM 2022년 11월 16일
편집: DGM 2022년 11월 16일
This is a very lazy answer. Consider this more a matter of cleanup than optimizing the object reconstruction. I'm not going to pretend that this is complete or robust.
img = imread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1195578/image.jpeg');
gray = rgb2gray(img); % convert to gray first; reduces cost of subsequent ops
gray = imrotate(gray,-90); % not every single output needs to be a unique variable
bw = ~imbinarize(gray); % equivalent to imcomplement(binaryimage)
se = strel('line',30,90); % idk why this was selected
bw = imopen(bw,se); % opening is equivalent to dilate(erode(x,se),se)
% opening with a fixed strel is idempotent
% i.e. opening again with the same strel does not change the result
bw = imclose(bw,strel('disk',100,0)); % fills some holes and closes some gaps
bw = bwareaopen(bw,10000); % gets rid of small specks
bwoutline = bwperim(bw);
% that 1px outline won't show up when rescaled here
% due to display interpolation.
% fatten the line so it shows up
bwoutline = imdilate(bwoutline,strel('disk',7));
Not really there, but it's ... what it is.