Call to Extract Contents from Cell Array not Equal to Value in Cell Array
Show older comments
Hello,
I am trying to extract the contents of a cell array to implement in my code (pasted below); however, the extracted contents add one more value than there is in that index of my cell array,
Index 3 of my array, "offY1" pasted directly into my cell array yields 870 . . . 2405
While a call to extract the value from my cell array "offY1{3}"[ yields 870 . . . 2406
I am very confused because I don't understand how a call directly to my cell array can result in a value different than the value in my cell array.
*** Code Below intends to blend the intersection of four stitched images**
clearvars
clc
close all
I1 = imread('I3.png');
I1 = rgb2gray((I1));
I2 = imread('I2.png');
I2 = rgb2gray((I2));
I3 = imread('I4.png');
I3 = rgb2gray((I3));
I4 = imread('I1.png');
I4 = rgb2gray((I4));
figure; imagesc(I1);
figure; imagesc(I2);
figure; imagesc(I3);
figure; imagesc(I4);
offsetY1 = 4;
offsetX1 = 732;
offsetY2 = 870;
offsetX2 = 1099;
offsetY3 = 773;
offsetX3 = 289;
% Unblended Full Image (2308, 3010)
fullIm = zeros(size(I1,1) + offsetY3 -1, size(I4,2) + 963 - 1, 'uint16');
% (4:1536, 732:2779)
fullIm(offsetY1:size(I1,1) + offsetY1 -1, offsetX1:size(I1,2) + offsetX1 - 1) = I2;
% (1:1536,1:2048)
fullIm(1:size(I1,1), 1:size(I1,2)) = I1;
% (870:2405,963:3010)
fullIm(offsetY2:size(I4,1) + offsetY2 -1, 963:size(I4,2) + 963 - 1) = I4;
% (773:2308,289:2336)
fullIm(offsetY3: size(I1,1) + offsetY3 -1, offsetX3:size(I3,2) + offsetX3 - 1) = I3;
figure; imagesc(fullIm);
% *** Need to edit from video tutorial below ***
% Blended Full Image (2308, 3010)
blendedFullIm = zeros(size(I4,1) + offsetY2 -1, size(I4,2) + 963 - 1, 'uint16');
blendedFullImNum = nan(size(I4,1) + offsetY2 -1, size(I4,2) + 963 - 1);
blendedFullImDen = nan(size(I4,1) + offsetY2 -1, size(I4,2) + 963 - 1);
% Averaging Mask
avgImFill = ones(size(I1));
I = {I1, I2, I3, I4};
offY1 = {offsetY1:size(I1,1) + offsetY1 - 1, 1:size(I1,1), offsetY2:size(I4,1) + offsetY2 -1, offsetY3: size(I1,1) + offsetY3 -1};
offX1 = {offsetX1:size(I1,2) + offsetX1 - 1, 1:size(I1,2), 963:size(I4,2) + 963 - 1, offsetX3:size(I3,2) + offsetX3 - 1};
for ti = 1:length(I)
% Blending Mask
BW = false(size(I{ti}) - 2);
BW = padarray(BW, [1,1]);
ED = bwdist(BW);
%setting up numerator/denominator
blendedFullImNum(offY1{ti},offX1{ti}) = nansum(cat(3, blendedFullImNum(offY1{ti},offX1{ti}),ED.*double(I{ti})),3);
blendedFullImDen(offY1{ti},offX1{ti}) = nansum(cat(3, blendedFullImNum(offY1{ti},offX1{ti}),ED),3);
end
blendedFullIm = blendedFullImNum / blendedFullImDen;
figure; imagesc(blendedFullIm);
Answers (1)
Oof. I didn't expect this. Can you find the tiny change I made here (other than line wrapping)?
offY1 = {offsetY1:size(I1,1) + offsetY1 - 1, ...
1:size(I1,1), ...
offsetY2:size(I4,1) + offsetY2 - 1, ...
offsetY3:size(I1,1) + offsetY3 - 1};
offX1 = {offsetX1:size(I1,2) + offsetX1 - 1, ...
1:size(I1,2), ...
963:size(I4,2) + 963 - 1, ...
offsetX3:size(I3,2) + offsetX3 - 1};
All I did was add some extra spaces. Consider the example
{1:10 -1}
{1:10 - 1}
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!