how to speed up basic image processing tasks
Mostra commenti meno recenti
Hi,
I'm trynig to explore the most basic image processing tasks and ideas with matlab. For that porpuse, I took a random image with the dimentions of 1200*900 pixels, loaded it to my matlab and got three matrixes in the same resolution, one for red, green and blue values in a pixel.
I tried to create a 1200*900 matrix that marks every dark-green pixel that was in the original image.
I made it with two 'for' loops.
I know that my code is far from perfect, but its not the important thing.
The problem is that the two 'for' loops taking few hours to complete, and I'm really surprised because 1200*900 its not that big size for an image and there's probably something really basic that I'm doing wrong. How can I preform those basic tasks faster?
picture = imread('1board.png')
darkcells (1200,900,3) = zeros
for i = 1:900
for j = 1:1200
if (( picture(i,j,1) < 40 ) && picture (i,j,1) > 19 ) == 1
darkcells (i,j,1) = 1
end
if (( picture(i,j,2) < 90 ) && picture (i,j,1) > 70 ) == 1
darkcells (i,j,2) = 1
end
if (( picture(i,j,3) < 75 ) && picture (i,j,1) > 55 ) == 1
darkcells (i,j,3) = 1
%and some additional code here.
end
end
Risposta accettata
Più risposte (1)
Image Analyst
il 10 Dic 2020
Try this:
rgbImage = imread('1board.png');
% Get masks for every color channel.
redMask = rgbImage(:,:,1) < 40 & rgbImage(:,:,1) > 19;
greenMask = rgbImage(:,:,2) < 90 & rgbImage(:,:,2) > 70;
blueMask = rgbImage(:,:,3) < 75 & rgbImage(:,:,3) > 55;
% Get the overall mask where all three are true.
darkcells = redMask & greenMask & blueMask;
% Display everything
subplot(1, 2, 1);
imshow(rgbImage);
subplot(1, 2, 2);
imshow(darkcells);
Or better yet, use the Color Thresholder app on the apps tab of the tool ribbon.
1 Commento
Solomon Margolin
il 15 Dic 2020
Categorie
Scopri di più su Debugging and Analysis in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!