二値化した画像を重ね合わせ等高線図みたいにしたい
18 views (last 30 days)
Show older comments
ある画像をそれぞれのしきい値(例:250、240、230・・・というような)で二値化処理し、
それぞれのしきい値で二値化した画像の白い領域の部分の色を変え(例:250の時赤、240の時青・・・といった感じ)
最後に色変えしたそれぞれのしきい値の二値化画像を重ね合わせて等高線図みたいな物を作りたいのですが
どなたかご教授お願いいたします。(下記のプログラムを改造または回答者様なりの方法でも構いません)
clear all;
close all;
% 各種定義
fig = 0;
for i=7
%Image Read
Imgfilename = strcat('./',num2str(i),'.jpg');
img=imread(Imgfilename);
gimg=rgb2gray(img);
BW = 250:5:255;
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');
% Filter image based on image properties.
BW_out = bwpropfilt(BW_out, 'Area', [10 + eps(10), Inf]);
% Get properties.
properties = regionprops(BW_out, {'Area'});
[~,num] = bwlabel(BW_out)
RGB(~cat(3,BW_out,BW_out,BW_out))=0;
end
0 Comments
Accepted Answer
Etsuo Maeda
on 31 Jan 2020
愚直にやるならこんなかんじですかね・・・
RGB = imread('peppers.png');
R = RGB(:, :, 1);
G = RGB(:, :, 2);
B = RGB(:, :, 3);
BW = rgb2gray(RGB);
map = jet(4) * 255;
for k = 1:4
TF = BW >= 64*(k-1) & BW <= 64*k -1 ;
R(TF) = map(k, 1);
G(TF) = map(k, 2);
B(TF) = map(k, 3);
end
sRGB(:, :, 1) = R;
sRGB(:, :, 2) = G;
sRGB(:, :, 3) = B;
imshow(sRGB)
More Answers (0)
See Also
Categories
Find more on オブジェクト解析 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!