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

9 次查看(过去 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 CenterFile Exchange 中查找有关 イメージ 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!