Is there a way to overcome For loops for fast processing?

2 ビュー (過去 30 日間)
Muhammad Farhan  Mughal
Muhammad Farhan Mughal 2019 年 9 月 9 日
コメント済み: darova 2019 年 9 月 10 日
I have written a following MATLAB code to detect skin color pixels from the RGB image. The output is as expected but being pixel by pixel algorithm, my program is taking too long, expecially for high quality images. Is there a way to take out the for loops for fast processing? Thank you.
[s1,s2,s3] = size(I);
skin_img1 = zeros(s1,s2,s3);
maxR = max(max(R));
minR = min(min(R));
maxG = max(max(G))
minG = min(min(G));
maxB = max(max(B));
minB = min(min(B));
for i = 1:s1
for j = 1:s2
if R(i,j)>90/255
if ( G(i,j)>40/255 && B(i,j)>20/255 && abs(R(i,j)-G(i,j))>15/255 && R(i,j)> G(i,j) && R(i,j) > B(i,j)...
&& (max([R(i,j),G(i,j),B(i,j)])- min([R(i,j),G(i,j),B(i,j)]) >15/255));
% (maxR - minR)>15/255 && (maxG - minG)>15/255 && (maxB - minB)>15/255 )
skin_img1(i,j,:) = I (i,j,:);
end
% else
% if( R(i,j)> G(i,j) && R(i,j) > B(i,j) && R(i,j) - G(i,j)> 5/255 && (abs(G(i,j)-B(i,j))>5/255))
% Skin_Image(i,j,:) = I (i,j,:);
% end
end
end
end
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 9 日
Attach sample image, so that we can try on it? Skin color?
Muhammad Farhan  Mughal
Muhammad Farhan Mughal 2019 年 9 月 10 日
One of the figure from internet is

サインインしてコメントする。

採用された回答

Muhammad Farhan  Mughal
Muhammad Farhan Mughal 2019 年 9 月 10 日
Following MATLAB code significantly reduced the computatonal cost of the questioned code
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
R = double(R);
G = double(G);
B = double(B);
R = R/255;
G = G/255;
B = B/255;
[s1,s2,s3] = size(I);
skin_img1 = zeros(s1,s2,s3);
index1 = zeros(size(R));
R1 = R(:) ; G1 = R(:); B1 = B(:);
mat_I = [R1,G1,B1]';
index = R >90/255 & G > 40/255 & B>20/255 & abs(R-G)>15/255 & R> G & R > B &...
reshape((max(mat_I)- min(mat_I)) >15/255, [s1,s2]);
index = uint8(index);
skin_img = repmat(index,[1,1,3]).*I;
  5 件のコメント
Muhammad Farhan  Mughal
Muhammad Farhan Mughal 2019 年 9 月 10 日
Yes, you can I also wrote that code for research purposes.
darova
darova 2019 年 9 月 10 日
download.jpg

サインインしてコメントする。

その他の回答 (1 件)

darova
darova 2019 年 9 月 9 日
See attached script
clc, clear
A = imread('masson.jpg');
subplot(1,2,1)
imshow(A)
RGB = [40 120 40]; % color you want
e = 40; % color shift / deviation
B = pix_in(A,RGB,e);
B = B + 255.*uint8(~B); % choosing white background
subplot(1,2,2)
imshow(B)
  7 件のコメント
Muhammad Farhan  Mughal
Muhammad Farhan Mughal 2019 年 9 月 10 日
No, I didn't.
darova
darova 2019 年 9 月 10 日
Good. Don't do this

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by