Bringing the RGB color back to image after processing

1 次查看(过去 30 天)
Hi, I am performing some type of processing on images due to which they are alligned with each other and are shifted in circular direction.
I want to bring the origional colors back to the images after the processing is completed. I have tried imposing the channel colors back but that didnt worked. It returned the images to its color and shape too.
Can anyone please guide me how can i achieve it?
Thanks a lot.

回答(2 个)

Ghulam
Ghulam 2018-2-27
Here is the code
if true
% code
FIXED = imread('a1.jpg');
MOVING1 = imread('a2.jpg');
MOVING2 = imread('a3.jpg');
MOVING3 = imread('a4.jpg');
MOVING4 = imread('a5.jpg');
% Convert RGB images to grayscale FIXED = rgb2gray(FIXED); MOVING1 = rgb2gray(MOVING1); MOVING2 = rgb2gray(MOVING2); MOVING3 = rgb2gray(MOVING3); MOVING4 = rgb2gray(MOVING4);
% Default spatial referencing objects fixedRefObj = imref2d(size(FIXED)); movingRefObj1 = imref2d(size(MOVING1)); movingRefObj2 = imref2d(size(MOVING2)); movingRefObj3 = imref2d(size(MOVING3)); movingRefObj4 = imref2d(size(MOVING4));
% Detect SURF features fixedPoints = detectSURFFeatures(FIXED,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5); movingPoints1 = detectSURFFeatures(MOVING1,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5); movingPoints2 = detectSURFFeatures(MOVING2,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5); movingPoints3 = detectSURFFeatures(MOVING3,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5); movingPoints4 = detectSURFFeatures(MOVING4,'MetricThreshold',750.000000,'NumOctaves',3,'NumScaleLevels',5);
% Extract features [fixedFeatures,fixedValidPoints] = extractFeatures(FIXED,fixedPoints,'Upright',false); [movingFeatures1,movingValidPoints1] = extractFeatures(MOVING1,movingPoints1,'Upright',false); [movingFeatures2,movingValidPoints2] = extractFeatures(MOVING2,movingPoints2,'Upright',false); [movingFeatures3,movingValidPoints3] = extractFeatures(MOVING3,movingPoints3,'Upright',false); [movingFeatures4,movingValidPoints4] = extractFeatures(MOVING4,movingPoints4,'Upright',false);
% Match features indexPairs1 = matchFeatures(fixedFeatures,movingFeatures1,'MatchThreshold',42.708333,'MaxRatio',0.427083); indexPairs2 = matchFeatures(fixedFeatures,movingFeatures2,'MatchThreshold',42.708333,'MaxRatio',0.427083); indexPairs3 = matchFeatures(fixedFeatures,movingFeatures3,'MatchThreshold',42.708333,'MaxRatio',0.427083); indexPairs4 = matchFeatures(fixedFeatures,movingFeatures4,'MatchThreshold',42.708333,'MaxRatio',0.427083);
fixedMatchedPoints1 = fixedValidPoints(indexPairs1(:,1)); fixedMatchedPoints2 = fixedValidPoints(indexPairs2(:,1)); fixedMatchedPoints3 = fixedValidPoints(indexPairs3(:,1)); fixedMatchedPoints4 = fixedValidPoints(indexPairs4(:,1));
movingMatchedPoints1 = movingValidPoints1(indexPairs1(:,2)); movingMatchedPoints2 = movingValidPoints2(indexPairs2(:,2)); movingMatchedPoints3 = movingValidPoints3(indexPairs3(:,2)); movingMatchedPoints4 = movingValidPoints4(indexPairs4(:,2));
MOVINGREG.FixedMatchedFeatures1 = fixedMatchedPoints1; MOVINGREG.FixedMatchedFeatures2 = fixedMatchedPoints2; MOVINGREG.FixedMatchedFeatures3 = fixedMatchedPoints3; MOVINGREG.FixedMatchedFeatures4 = fixedMatchedPoints4;
MOVINGREG.MovingMatchedFeatures1 = movingMatchedPoints1; MOVINGREG.MovingMatchedFeatures2 = movingMatchedPoints2; MOVINGREG.MovingMatchedFeatures3 = movingMatchedPoints3; MOVINGREG.MovingMatchedFeatures4 = movingMatchedPoints4;
% Apply transformation - Results may not be identical between runs because of the randomized nature of the algorithm tform1 = estimateGeometricTransform(movingMatchedPoints1,fixedMatchedPoints1,'affine'); tform2 = estimateGeometricTransform(movingMatchedPoints2,fixedMatchedPoints2,'affine'); tform3 = estimateGeometricTransform(movingMatchedPoints3,fixedMatchedPoints3,'affine'); tform4 = estimateGeometricTransform(movingMatchedPoints4,fixedMatchedPoints4,'affine');
MOVINGREG.Transformation1 = tform1; MOVINGREG.Transformation2 = tform2; MOVINGREG.Transformation3 = tform3; MOVINGREG.Transformation4 = tform4;
MOVINGREG.RegisteredImage1 = imwarp(MOVING1, movingRefObj1, tform1, 'OutputView', fixedRefObj, 'SmoothEdges', true); MOVINGREG.RegisteredImage2 = imwarp(MOVING2, movingRefObj2, tform2, 'OutputView', fixedRefObj, 'SmoothEdges', true); MOVINGREG.RegisteredImage3 = imwarp(MOVING3, movingRefObj3, tform3, 'OutputView', fixedRefObj, 'SmoothEdges', true); MOVINGREG.RegisteredImage4 = imwarp(MOVING4, movingRefObj4, tform4, 'OutputView', fixedRefObj, 'SmoothEdges', true);
% Store spatial referencing object MOVINGREG.SpatialRefObj = fixedRefObj; time= toc; fprintf('The time of execution was %6.2fs\n\n',time);
%Display the image at the end % imshow(MOVINGREG.RegisteredImage1,'Border','tight') figure; % pos1 = [0 -0.1 0.4 1]; % subplot('Position',pos1); imshow(MOVINGREG.RegisteredImage1) % % truesize(MOVINGREG.RegisteredImage1,[100 100]) % pos2 = [0.4 0 0.75 1]; % subplot('Position',pos2); imshow(MOVINGREG.RegisteredImage1) subplot(3,3,4); imshow(MOVINGREG.RegisteredImage1) subplot(3,3,5); imshow(FIXED) subplot(3,3,6); imshow(MOVINGREG.RegisteredImage2) subplot(3,3,8); imshow(MOVINGREG.RegisteredImage3) subplot(3,3,2); imshow(MOVINGREG.RegisteredImage4)
end

Ghulam
Ghulam 2018-2-27
I dont know why the code attachment is having problem.

类别

Help CenterFile Exchange 中查找有关 Feature Detection and Extraction 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by