牛全体の画像から耳標部分を取り出したい

조회 수: 12 (최근 30일)
あ
2022년 12월 20일
편집: Kojiro Saito 2023년 1월 6일
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
  댓글 수: 2
Kojiro Saito
Kojiro Saito 2022년 12월 20일
@勇威 池畑さん、ご質問ありがとうございます。コードを記載いただいていますが、どこが聞きたい質問でしょうか? タイトルにやりたいことは書かれていますが、どこでエラーが出てしまうとか、どこがうまくいかない、とか書いていただけると回答を得やすいと思います。
あ
2022년 12월 20일
現在は上のプログラミングから耳標部分をトリミングした画像では光学式文字認識を使って文字認識することができます。
今回は牛全体から耳標部分を取り出そうと考えております。自分では耳標が黄色なので閾値を用いて取り出せるのではないかと考えております。そして閾値の設定で困っています。
つたない文章で申し訳ございません。アドバイス宜しくお願いします。
下が現在考えているプログラミングです。
clear all;close all;clc
I = imread('\耳標写真\牛舎.png');
HSV = rgb2hsv(I);
Hue = HSV(:,:,1);
Hue = HSV(:,:,2);
Hue = HSV(:,:,3);
figure,
%subplot(2,2,1),
figure,imshow(Hue,"InitialMagnification","fit")
impixelinfo

댓글을 달려면 로그인하십시오.

답변 (1개)

Hernia Baby
Hernia Baby 2022년 12월 20일
もし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
  댓글 수: 1
あ
2022년 12월 20일
ありがとうございました。活用させていただきます!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!