Creating an image from RGB values at each step. How to?
2 次查看(过去 30 天)
显示 更早的评论
I want to have a rgb matrix from the rgb values i am getting at each step of the for loop. And I want to create a new image with every pixel rgb data to be at the same location as the row and col in operation. My code is as follows:
numberOfImages=5;
finalRGBImageMatrix=zeros(1584,2780,3); for row=390:392 for col=498:500
for i=1:numberOfImages
filename=[num2str(i), '.png'];
rgbImage=imread(filename, 'png');
R = rgbImage(row, col, 1);
G = rgbImage(row, col, 2);
B = rgbImage(row, col, 3);
RGBMatrix(i,:) =[R,G,B];
end
for imageNumber=1:numberOfImages
match=0;
jitter=0;
for j=numberOfImages:-1:1
RedChannelDifference=abs(double(RGBMatrix(j,1))-double(RGBMatrix(imageNumber,1)));
GreenChannelDifference=abs(double(RGBMatrix(j,2))-double(RGBMatrix(imageNumber,2)));
BlueChannelDifference=abs(double(RGBMatrix(j,3))-double(RGBMatrix(imageNumber,3)));
if (RedChannelDifference+GreenChannelDifference+BlueChannelDifference)<=10
jitter=jitter+RedChannelDifference+GreenChannelDifference+BlueChannelDifference;
match=match+1;
end
end
match=match-1;
matchMatrixOfAllImages(imageNumber,:)=[match];
end
%fprintf('The maximum value of matches is : %d \n', max(matchMatrixOfAllImages(:)));
index=find(matchMatrixOfAllImages == max(matchMatrixOfAllImages(:)));
if size(index,1)>1
jitterMatrixOfAllImages(imageNumber,:)=[jitter];
%fprintf('Jitter values of ONLY MATCHES');
jitterMatrixOfMatchedImages=jitterMatrixOfAllImages(index,:);
indexForJitter=find(jitterMatrixOfMatchedImages == min(jitterMatrixOfMatchedImages(:)));
if size(indexForJitter,1)>1
indexOfPictureNeeded=indexForJitter(1,:);
filenameOfImage1=[num2str(indexOfPictureNeeded), '.png'];
rgbImage1=imread(filename, 'png');
R1 = rgbImage1(row, col, 1);
G1 = rgbImage1(row, col, 2);
B1 = rgbImage1(row, col, 3);
RGBMatrix1(indexOfPictureNeeded,:) =[R1,G1,B1]
else
indexOfPictureNeeded=indexForJitter(1,:);
filenameOfImage1=[num2str(indexOfPictureNeeded), '.png'];
rgbImage1=imread(filename, 'png');
R1 = rgbImage1(row, col, 1);
G1 = rgbImage1(row, col, 2);
B1 = rgbImage1(row, col, 3);
RGBMatrix1(indexOfPictureNeeded,:) =[R1,G1,B1]
end
else
%fprintf('Single');
indexOfPictureNeeded1=indexForJitter(1,:);
filename1=[num2str(indexOfPictureNeeded1), '.png'];
rgbImage2=imread(filename, 'png');
R1 = rgbImage2(row, col, 1);
G1 = rgbImage2(row, col, 2);
B1 = rgbImage2(row, col, 3);
RGBMatrix2(indexOfPictureNeeded1,:) =[R1,G1,B1]
finalRGBImageMatrix(:,:,i) = [i, i+1; i^2, i/2];
end
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Segmentation and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!