Convert a RGB image to gray with parallel processing?
17 views (last 30 days)
Show older comments
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');
0 Comments
Answers (2)
KSSV
on 4 Nov 2021
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) ;
yanqi liu
on 4 Nov 2021
Edited: yanqi liu
on 4 Nov 2021
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
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!