Home > Back-end >  Matlab image processing threshold segmentation
Matlab image processing threshold segmentation

Time:11-05

When I do you encountered a problem, use matlab for establishing an RGB image brightness and saturation threshold, brightness threshold is (I=+ Ig + Ib (Ir)/3) & gt; Ta * Imax, Imax is the biggest I, of all the pixel saturation threshold is
(S=1 - min (Ir, Ib, Ig)/I) & lt; Tb * Smax, Smax is the biggest S of all pixels, below is my code, want to ask where there is a problem:

close all; clear all; clc;
I=imread (' test. JPG);
R=I;
R (:, :, 2)=0.
R (:, :, 3)=0.
G=I;
G (:, :, 1)=0;
G (:, :, 3)=0.
B=I;
B (:, :, 1)=0.
B (:, :, 2)=0.
[m, n]=size (I);
Ta=0.5;
Tb=0.5;
Imax=0;
Smax=0;
% look for Imax and Smax
For I=1: m
For j=1: n
I0=(R (I, j) + G (I, j) + B (I, j))/3;
If I0 & gt; Imax
Imax=";
End
M=[R (I, j), G (I, j), B (I, j)];
Min=Min (M);
S0=1 - Min/I0;
If S0 & gt; Smax
Smax=S0;
End
End
End
% threshold segement
Inew=I;
For I=1: m
For j=1: n
I1=(R (I, j) + G (I, j) + B (I, j))/3;
M=[R (I, j), G (I, j), B (I, j)];
Min=Min (M);
S1=1 - Min/I1;
If (I1 & lt;=Ta * ImaxS1 & gt; Smax=Tb *)
Inew (I, j)=0.
End
End
End
Figure,
Subplot (121), imshow (I);
Subplot (122), imshow (Inew);
  • Related