how to remove the pixels under the curve on image
2 views (last 30 days)
Show older comments
I have attatche my image.
0 Comments
Answers (2)
Mark Sherstan
on 15 Dec 2018
I closed the area with another orange line and got this result. It is a little rough and can be refined but should push you in the right direction. Let me know if you have any questions.
I = imread('img.jpg');
[BW,maskedRGBImage] = createMask(I);
imshow(maskedRGBImage)
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder app. The colorspace and
% range for each channel of the colorspace were set within the app. The
% segmentation mask is returned in BW, and a composite of the mask and
% original RGB images is returned in maskedRGBImage.
% Auto-generated by colorThresholder app on 14-Dec-2018
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.000;
channel1Max = 0.123;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.415;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Added some extra processing
BW2 = imfill(BW,'holes');
BW3 = bwareafilt(BW2,1);
BW = imcomplement(BW3);
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
0 Comments
DGM
on 1 Dec 2022
If you're already using drawPolygon(), use it to create a mask directly by either right-clicking on the ROI or by using createMask on the created object. That makes a lot more sense than taking a screenshot of a figure and then trying to do color-based segmentation of a screenshot which has no geometric relationship to the original image.
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!