しきい値ごとの面積を計算 グラフ作成

11 ビュー (過去 30 日間)
kou
kou 2020 年 1 月 17 日
コメント済み: kou 2020 年 1 月 20 日
ある一枚の画像を対象に0から255のしきい値で二値化しそれぞれのしきい値の時のピクセル値を求めて
横軸を0から255 縦軸をそれぞれのしきい値の時に求めたピクセル値をプロットしたグラフ作成したいのですが、
どのようにすればいいのでしょうか。どなたかご教授お願いいたします。
また、それぞれのしきい値での二値化された画像を一つのフィギュアにまとめて載せたいのですが、上書きされて一枚しか表示されません。合わせてお願いいたします。
clear all;
close all;
% 各種定義
fig = 0;
for i=1
%Image Read
Imgfilename = strcat('./',num2str(i),'.jpg');
img=imread(Imgfilename);
gimg=rgb2gray(img);
for j=0:255
BW = gimg>j;
BW2 = medfilt2(BW);
BW3 = imfill(BW2,'holes');
BW4 = im2uint8(BW3);
BW_out = BW;
% Remove portions of the image that touch an outside edge.
BW_out = imclearborder(BW_out);
% Fill holes in regions.
BW_out = imfill(BW_out, 'holes');
BW_out = bwpropfilt(BW_out, 'Area', [20, 526]);
% Get properties.
properties = regionprops(BW_out, {'Area'});
B=bwarea(BW);
end
end

採用された回答

Kenta
Kenta 2020 年 1 月 18 日
こんにちは、以下のようにすればできます。
「縦軸をそれぞれのしきい値の時に求めたピクセル値」とは、変数Bのことで正しいでしょうか。
上は閾値ごとに2値化したもの、下が、Bをプロットした図です。
example.jpg
plots.jpg
clear;clc;close all;
for i=1
%Image Read
% Imgfilename = strcat('./',num2str(i),'.jpg');
% img=imread(Imgfilename);
img=imread('onion.png');
gimg=rgb2gray(img);
range=[0:5:255];
% define the cell variable for montage display
C=cell(numel(range)+1,1);
numPixel=zeros(numel(range),1);
C{1}=img;
count=1;
for j=range
BW = gimg>j;
BW2 = medfilt2(BW);
BW3 = imfill(BW2,'holes');
BW4 = im2uint8(BW3);
BW_out = BW;
% Remove portions of the image that touch an outside edge.
BW_out = imclearborder(BW_out);
% Fill holes in regions.
BW_out = imfill(BW_out, 'holes');
BW_out = bwpropfilt(BW_out, 'Area', [1, 1000]);
% insert a title for the threshold determination
BW_out = insertText(double(BW_out),[round(size(BW,2)/3),1], ...
strcat('j:',num2str(j)),'FontSize',18,'BoxOpacity',0.4,'TextColor','white');
C{count+1}=BW_out;
% Get properties.
properties = regionprops(BW_out, {'Area'});
B=bwarea(BW);
numPixel(count)=B;
count=count+1;
end
end
figure;montage(C)
figure;plot(numPixel)
  1 件のコメント
kou
kou 2020 年 1 月 20 日
無事できました。ありがとうございます!

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchangeイメージ についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!