How do I repair noisy picture and invert the bw color?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello, new to the matlab app, I'm trying to repair this image
to be like this picture (or close)
Any help would be much appreciated.
Thanks.
채택된 답변
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
% added
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));
imshow(bwoutline);
Not really there, but it's ... what it is.
댓글 수: 3
DGM
2022년 11월 16일
I edited it to include that. I didn't really consider the example to be complete enough to warrant the window dressing, but I suppose completion isn't my judgement call to make.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!