How do I repair noisy picture and invert the bw color?

조회 수: 2 (최근 30일)
Dustkin Jou
Dustkin Jou 2022년 11월 16일
댓글: Dustkin Jou 2022년 11월 17일
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.
  댓글 수: 2
Rik
Rik 2022년 11월 16일
What have you tried so far?
Dustkin Jou
Dustkin Jou 2022년 11월 16일
using this
clc;
close all;
clearvars;
img = imread('7.jpg');
rotated = imrotate(img,-90);
gray = rgb2gray(rotated);
bw = imbinarize(gray);
comp = imcomplement(bw);
se = strel('line',30,90);
erode = imerode(comp,se);
dil = imdilate(erode,se);
erode1 = imerode(dil,se);
dil1 = imdilate(erode1,se);
figure(1);
imshow(dil1);
this is the output, im trying to get smoother in the tip and bottom

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

채택된 답변

DGM
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
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.
Dustkin Jou
Dustkin Jou 2022년 11월 17일
Thank you. This is the output i was looking for, thank you so much

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Modify Image Colors에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by