Convert a RGB image to gray with parallel processing?
Afficher commentaires plus anciens
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');
Réponses (2)
KSSV
le 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) ;
1 commentaire
thanh nguyen
le 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
Catégories
En savoir plus sur Image Preview and Device Configuration dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!