Convert a RGB image to gray with parallel processing?
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
KSSV
el 4 de Nov. de 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
el 4 de Nov. de 2021
Editada: yanqi liu
el 4 de Nov. de 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 comentarios
Ver también
Categorías
Más información sobre Image Preview and Device Configuration en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!