필터 지우기
필터 지우기

How to manually remove the unwanted data dots or lines in a graph?

조회 수: 14 (최근 30일)
xiaobo wu
xiaobo wu 2024년 4월 24일
답변: xiaobo wu 2024년 4월 25일
I want to know if a function exists to manually remove the dots in an image like this. In this image, the unwanted dots are in the red circle. I hope I can use something like a brush to remove them and let them become the black background. Any suggestion is appreciated!
  댓글 수: 1
Deepu
Deepu 2024년 4월 24일
To manually remove unwanted dots or lines in an image like the one you provided using MATLAB, you can use the roipoly function to interactively draw a region of interest (ROI) around the unwanted areas and then set those regions to black. Here's a step-by-step guide:
  1. Load the image into MATLAB.
  2. Display the image using imshow.
  3. Use roipoly to interactively draw polygons around the unwanted areas.
  4. Set the selected regions to black in the image matrix.
  5. Display the modified image using imshow.
Here's a sample code to achieve this:
% Load the image
image = imread('your_image.png');
% Display the image
imshow(image);
% Interactive ROI selection
h = msgbox('Draw a polygon around the unwanted areas. Double-click to finish.');
pause(1); % Wait for the user to acknowledge
% Get the ROI polygon
roi_mask = roipoly;
% Set the selected regions to black
image(repmat(~roi_mask, [1, 1, size(image, 3)])) = 0;
% Display the modified image
figure;
imshow(image);
This code will allow you to draw polygons around the unwanted areas of the image, and the selected regions will be set to black. Adjust the size and shape of the ROI as needed by drawing multiple polygons or refining the existing ones.

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

채택된 답변

DGM
DGM 2024년 4월 24일
편집: DGM 2024년 4월 25일
Use bwareafilt() (or maybe bwareaopen()) on the mask before creating the composite image. Composite images like this should be treated like graphs. They're output visualizations to look at. It's usually unnecessary for technical purposes, and trying to reprocess them only invites unnecessary complications and potential errors.
Here are some examples of options. This is a rough mask with one main object selection and a bunch of extraneous junk surrounding it.
mask = imread('roughpepmask.png'); % logical
% keep only blobs above a certain size
mask = bwareaopen(mask,500); % adjust the area to suit your needs
imshow(mask,'border','tight')
mask = imread('roughpepmask.png'); % logical
% keep only the largest blob from the mask
mask = bwareafilt(mask,1); % pick how many
imshow(mask,'border','tight')
Interactive things like ginput() and drawpolygon() don't work on the forum, but you can run these examples with the attached file.
mask = imread('roughpepmask.png'); % logical
% interactively select the single blob you want
imshow(mask);
[x y] = ginput(1); % click on the blob with the mouse
mask = bwselect(mask,x,y); % get that blob
imshow(mask,'border','tight')
mask = imread('roughpepmask.png'); % logical
% interactively select the ROI using a polygon
imshow(mask);
ROI = drawpolygon(gca); % use the mouse to draw a polygon around the blob
mask = mask & createMask(ROI); % intersection of mask & ROI
imshow(mask,'border','tight')
Output composition can be done logically or by multiplication. There are many many examples on the forum.
inpict = imread('peppers.png');
% the MIMT way (class & depth agnostic)
%outpict = replacepixels(inpict,0,mask);
% logical addressing (assuming input class is uint or float)
%outpict = inpict;
%outpict(repmat(~mask,[1 1 size(inpict,3)])) = 0;
% multiplicative (assuming input class is uint or float)
outpict = cast(double(inpict).*mask,class(inpict));
imshow(outpict,'border','tight')
Again, the spatial information that's important to keep is the mask, not this composite image.

추가 답변 (1개)

xiaobo wu
xiaobo wu 2024년 4월 25일
Thank you @Deepu and @DGM I will try your methods when I am available and let you know the results. From the produced images, it is encouraging you may help me fix my issues. Thank you all again!

Community Treasure Hunt

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

Start Hunting!

Translated by