remove backgroung from the image
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Can you help me to remove the backgrond from the image?
this is example of image

採用された回答
Image Analyst
2021 年 4 月 14 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
