牛全体の画像から耳標部分を取り出したい
8 views (last 30 days)
Show older comments
clear all,close all
I = imread(['\耳標写真\252.jpg']);
%figure,imshow(I)
I_2 = yellowMask(I);
% figure,imshow(I_2,"InitialMagnification","fit")
I_3=imfill(I_2,'holes');
figure,imshow(I_3,"InitialMagnification","fit")
I_4 = repmat(I_3,[1 1 3]);
I_4 = uint8(I_4);
I_5 = I(:,:,:).*I_4(:,:,:);
figure,imshow(I_5,"InitialMagnification","fit")
% impixelinfo
% I_6 = createMask2(I_5);
%figure,imshow(I_6,"InitialMagnification","fit")
% impixelinfo
Ig = rgb2gray(I_5);
figure,imshow(Ig,"InitialMagnification","fit")
% impixelinfo
Ig2=Ig(:,:)<150&Ig(:,:)>10;
% figure,imshow(Ig2,"InitialMagnification","fit")
Ig3 = bwareaopen(Ig2,50);
figure,imshow(Ig3,"InitialMagnification","fit")
%
% J = histeq(Ig);
%
% BW = imbinarize(J);
% BW=uint8(BW);
% BW1=BW.*255;
% % figure,imshow(BW1,"InitialMagnification","fit")
% % impixelinfo
results = ocr(Ig3);
results.Text
results = ocr(Ig3,'CharacterSet','0123456789','TextLayout','Block');
results.Text
Answers (1)
Hernia Baby
on 20 Dec 2022
もしyellowMask関数を作りたいのであれば、
色の閾値アプリケーションの使用をオススメします。
I = imread('peppers.png');
[~,I2] = yellowMask(I);
montage({I,I2})
以下はアプリで作った関数です

function [BW,maskedRGBImage] = yellowMask(RGB)
I = rgb2hsv(RGB);
channel1Min = 0.092;
channel1Max = 0.146;
channel2Min = 0.352;
channel2Max = 1.000;
channel3Min = 0.850;
channel3Max = 1.000;
% Create mask based on chosen histogram thresholds
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
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!