Convert a RGB image to gray with parallel processing?
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
KSSV
am 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
am 4 Nov. 2021
Bearbeitet: yanqi liu
am 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 Kommentare
Siehe auch
Kategorien
Mehr zu Image Preview and Device Configuration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!