Convert a RGB image to gray with parallel processing?
이전 댓글 표시
I have this code under, that is convert RGB to gray, but i don't how to do with parallel processing?Any one know , help me pls
Im=imread('5.jpg');
%0.2989 * R + 0.5870 * G + 0.1140 * B
GIm=uint8(zeros(size(Im,1),size(Im,2)));
tic
for i=1:size(Im,1)
for j=1:size(Im,2)
GIm(i,j)=0.2989*Im(i,j,1)+0.5870*Im(i,j,2)+0.1140*Im(i,j,3);
end
end
toc
subplot(1,2,1), imshow(Im), title('RGB Scale image');
subplot(1,2,2), imshow(GIm), title('Gray Scale image');
답변 (2개)
KSSV
2021년 11월 4일
You need not to use a loop here and parallel computing. Just the below should work.
Im=imread('5.jpg');
%0.2989 * R + 0.5870 * G + 0.1140 * B
GIm=0.2989*Im(:,:,1)+0.5870*Im(:,:,2)+0.1140*Im(:,:,3);
GIM = uint8(GIm) ;
clc; clear all; close all
Im=imread('football.jpg');
%0.2989 * R + 0.5870 * G + 0.1140 * B
GIm=uint8(zeros(size(Im,1),size(Im,2)));
GIm2=uint8(zeros(size(Im,1),size(Im,2)));
tic
for i=1:size(Im,1)
for j=1:size(Im,2)
GIm(i,j)=0.2989*Im(i,j,1)+0.5870*Im(i,j,2)+0.1140*Im(i,j,3);
end
end
toc
parpool(3)
tic
parfor i=1:size(Im,1)
for j=1:size(Im,2)
GIm2(i,j)=0.2989*Im(i,j,1)+0.5870*Im(i,j,2)+0.1140*Im(i,j,3);
end
end
toc
카테고리
도움말 센터 및 File Exchange에서 Image Preview and Device Configuration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!