フィルターのクリア

How to fill the image of the bottle with black color?

1 回表示 (過去 30 日間)
Bella
Bella 2017 年 1 月 23 日
編集済み: Bella 2017 年 1 月 24 日
Hi,
I want to fill the image of the bottle with black color. I need to modify my coding. Need help from someone.
clear;close all;
% Load image
I=imread('C:\Users\Nabilah Syazana\Desktop\Reference\Reference Image\Ref_Red.jpg');
%Threshold & Segment image
BW=adaptivethreshold(I,50,0.06,0);
figure; imshow(I);
figure; imshow(BW);
% Calculate Area, Perimente, Extent, Major Axis and Minor Axis
Measurements = regionprops(BW, 'Area', 'Perimeter', 'Extent', 'MajorAxisLength', 'MinorAxisLength');
Area1 = [Measurements.Area];
Perimeter1 = [Measurements.Perimeter]
Area = sum(Area1)
Perimeter = sum(Perimeter1)
function bw=adaptivethreshold(IM,ws,C,tm)
%ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the
%foreground from the background with nonuniform illumination.
% bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local
% threshold mean-C or median-C to the image IM.
% ws is the local window size.
% tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median.
if (nargin<3)
error('You must provide the image IM, the window size ws, and C.');
elseif (nargin==3)
tm=0;
elseif (tm~=0 && tm~=1)
error('tm must be 0 or 1.');
end
IM=mat2gray(IM);
if tm==0
mIM=imfilter(IM,fspecial('average',ws),'replicate');
else
mIM=medfilt2(IM,[ws ws]);
end
sIM=mIM-IM-C;
bw=im2bw(sIM,0);
bw=imcomplement(bw);
Below is my sample image
  1 件のコメント
abuzer
abuzer 2017 年 1 月 23 日
Firstof all you can try strel function for closing area than delete upside of bottle with area threshold than use imfill.ı hopeit helps

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2017 年 1 月 23 日
Try the attached file.
  1 件のコメント
Bella
Bella 2017 年 1 月 24 日
編集済み: Bella 2017 年 1 月 24 日
Thanks for helping me. I got it! :)

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 1 月 23 日
Did you try varying the windowsize and C value?
  1 件のコメント
Bella
Bella 2017 年 1 月 24 日
not yet. I don't know how to do it.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by