remove backgroung from the image
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Can you help me to remove the backgrond from the image?
this is example of image

채택된 답변
Image Analyst
2021년 4월 14일
0 개 추천
Try the Color Thresholder. Use HSV color space and adjust the S slider. Or the V slider. Then tell it to export the code.
댓글 수: 7
Frisda Sianipar
2021년 4월 14일
편집: Walter Roberson
2021년 7월 13일
This code is for image segmentation from removing background - green channel - clahe - canny. But in this code we still input images one by one And I want the code to immediately read all the images in one folder and save the output in another folder. Can you help me? Please, thankyou in advance
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 16;
%===============================================================================
% Get the name of the image the user wants to use.
baseFileName = 'image.jpg';
folder = pwd;
fullFileNam
e = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
%=======================================================================================
% Read in demo image.
rgbImage = imread(fullFileName);
% Get the dimensions of the image.
% [rows, columns, numberOfColorChannels] = size(rgbImage)
% Display image.
figure(1);
imshow(rgbImage, []);
impixelinfo;
axis on;
caption = sprintf('Original Color Image\n%s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
hp = impixelinfo(); % Set up status line to see values when you mouse over the image.
% Set up figure properties:
% Enlarge figure to full screen.
% set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0.05 1 0.95]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
% set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% drawnow;
[mask, maskedRGBImage] = createMask(rgbImage);
% Extract the largest blob only. That will be the hand.
mask = bwareafilt(mask, 1);
% Mask the image using bsxfun() function to multiply the mask by each channel individually.
maskedRgbImage = bsxfun(@times, rgbImage, cast(mask, 'like', rgbImage));
% Display the image.
figure(2);
imshow(maskedRgbImage, []);
% impixelinfo;
% title('Masked Image', 'FontSize', fontSize, 'Interpreter', 'None');
axis on;
drawnow;
%green channel
green_channel = maskedRgbImage(:,:,2);
figure(3),imshow(green_channel)
%CLAHE
CLAHE = adapthisteq(green_channel);
figure, fig4=imshow(CLAHE);
%Canny
ER = edge(CLAHE, 'canny');
EG = edge(CLAHE, 'canny');
EB = edge(CLAHE, 'canny');
anyedge = ER | EG | EB;
figure,fig5=imshow(anyedge);
% [n, r] = fboxcount(anyedge,'slope');
% df = -diff(log(n))./diff(log(r));
% %Menampilkan hasil dimensi
% disp(['Df= ' num2str(mean(df(4:8)))]);
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 11-Aug-2018
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.000;
channel1Max = 1.000;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.215;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.082;
channel3Max = 0.810;
% 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;
% 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
Image Analyst
2021년 4월 14일
Code samples are in the FAQ:
Frisda Sianipar
2021년 4월 15일
Thank you sir, i will try
Frisda Sianipar
2021년 4월 15일
But sir i want to save all the output automatic
Image Analyst
2021년 4월 15일
What's not automatic about it? Once you've defined the thresholds, you can apply it to image after image automatically with no further user involvement needed.
Frisda Sianipar
2021년 4월 15일
save the output of segmentation sir
Walter Roberson
2021년 7월 13일
You can use sprintf() or compose() to generate filenames, and call save() passing in the file name and the name of the variable to save.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Color에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
