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

15 vues (au cours des 30 derniers jours)
kou
kou le 17 Jan 2020
Commenté : kou le 20 Jan 2020
ある一枚の画像を対象に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

Réponse acceptée

Kenta
Kenta le 18 Jan 2020
こんにちは、以下のようにすればできます。
「縦軸をそれぞれのしきい値の時に求めたピクセル値」とは、変数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 commentaire
kou
kou le 20 Jan 2020
無事できました。ありがとうございます!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur イメージ dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!