二値化した画像を重ね合わせ等高線図みたいにしたい

4 次查看(过去 30 天)
kou
kou 2020-1-23
评论: kou 2020-2-3
ある画像をそれぞれのしきい値(例: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

采纳的回答

Etsuo Maeda
Etsuo Maeda 2020-1-31
愚直にやるならこんなかんじですかね・・・
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)
  1 个评论
kou
kou 2020-2-3
ありがとうございます。

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Marine and Underwater Vehicles 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!