I want to code an image stabilizer but when I try to copy an RGB image to a m*n*3 zeros matrix and display it I get a weird result.
조회 수: 1 (최근 30일)
이전 댓글 표시
Reinhold Erwin Suchowitzky Toba
2023년 3월 10일
댓글: Reinhold Erwin Suchowitzky Toba
2023년 3월 10일
My problem is in the "% Corrected image" section, here is my code (I attached the images I'm using):
close all; clear all; clc;
% Image loading
imds = imageDatastore('blablabla');
images = readall(imds);
% Centroid calculation
centroid1 = centroidFinder(images{1});
centroid2 = centroidFinder(images{2});
% Centroid difference
centroidD = centroid2-centroid1;
% Corrected image
sizeI = size(images{1});
correctedDim1 = sizeI(1)+abs(centroidD(1)); correctedDim2 = sizeI(2)+abs(centroidD(2)); correctedDim3 = sizeI(3);
correctedI = zeros(correctedDim1, correctedDim2, correctedDim3);
correctedI(1:1:sizeI(1), 1:1:sizeI(2), :) = images{2};
imshow(correctedI);
function centroid = centroidFinder(image)
%{ NOTE: Add a range for G2 %}
[R,G,B] = imsplit(image); % RGB image split
G2 = G == max(max(G)); % Discard of elements not belinging to G
C = regionprops(true(size(G2)),G2,'WeightedCentroid'); % Centroid calculation
centroid = [round(C.WeightedCentroid(1)), round(C.WeightedCentroid(2))]; % Centroid vector output
end
댓글 수: 0
채택된 답변
DGM
2023년 3월 10일
Since the expected scale of image data depends on the class of the array, you need to make sure that the array is the appropriate class for the data you're putting in it.
correctedI = zeros(correctedDim1, correctedDim2, correctedDim3, 'uint8');
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!