how to remove the pixels under the curve on image

조회 수: 5(최근 30일)
Sulochana S
Sulochana S 2018년 12월 5일
답변: DGM 2022년 12월 1일
I have attatche my image.

답변(2개)

Mark Sherstan
Mark Sherstan 2018년 12월 15일
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.
untitled.png
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

DGM
DGM 2022년 12월 1일
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.

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by