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

조회 수: 10 (최근 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!