- Load the image into MATLAB.
- Display the image using imshow.
- Use roipoly to interactively draw polygons around the unwanted areas.
- Set the selected regions to black in the image matrix.
- Display the modified image using imshow.
How to manually remove the unwanted data dots or lines in a graph?
15 次查看(过去 30 天)
显示 更早的评论
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
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:
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
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.
0 个评论
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!