return matlab中索引图像的索引值
return index value from index image in matlab
我想在 Matlab 中从特定坐标 (X, Y)
的索引图像中提取索引值。
我使用了 impixel
,它非常适合图像,但是,当我在循环中使用它时,它 returns NaN 或不正确的值。
filename = 'realworldCoordinates.txt'; % define the file name
delimiterIn = ''; % set parameter for seperating values
headerlinesIn = 1; %which line is header
[A] = importdata (filename);
I = A.data (:,:);
X1 = II(:,1); %define X1
Y1 = II(:,2); % define Y1
X2 = II(:,3); %define X2
Y2 = II(:,4); %define Y2
for k = 1: numel (Imfiles(1:2))
fileNames = Imfiles(k).name;
imIndexed = imread (fileNames);
Z1 = impixel (imIndexed(:,:,3), X1,Y1);
Z2 = impixel (imIndexed(:,:,3), X2,Y2);
end
由于我没有你的完整代码,我只能假设一些关于正在发生的事情,而不能实际尝试这个解决方案来看看它是否能满足你的要求。首先,我不确定 impixel 是否应该支持仅传递您使用 imIndexed(:,:,3)
处理的每个像素的第三个元素,而是您应该在使用 impixel 后获得第三个元素。尝试做这样的事情:
for k = 1: numel (Imfiles(1:2))
fileNames = Imfiles(k).name;
imIndexed = imread (fileNames);
tmp1 = impixel (imIndexed, X1,Y1);
tmp2 = impixel (imIndexed, X2,Y2);
Z1 = tmp1(3);
Z2 = tmp2(3);
end
根据@mike Thomson 的建议,我将我的代码修改如下:
filename = 'realworldCoordinates.txt'; % define the file name
delimiterIn = ''; % set parameter for seperating values
headerlinesIn = 1; %which line is header
[A] = importdata (filename);
I = A.data (:,:);
X1 = II(:,1); %define X1
Y1 = II(:,2); % define Y1
X2 = II(:,3); %define X2
Y2 = II(:,4); %define Y2
%loop for reading data from txt file and return the index value
for k = 1: numel (Imfiles(1:2))
fileNames = Imfiles(k).name;
imIndexed = imread (fileNames);
Z1 = impixel (imIndexed(:,:,3), X1(k),Y1(k));
Z1(k,:) =(Z1(:,:,1))
Z2 = impixel (imIndexed(:,:,3), X2(k),Y2(k));
Z2(k,:) =(Z2(:,:,1))
end
我想在 Matlab 中从特定坐标 (X, Y)
的索引图像中提取索引值。
我使用了 impixel
,它非常适合图像,但是,当我在循环中使用它时,它 returns NaN 或不正确的值。
filename = 'realworldCoordinates.txt'; % define the file name
delimiterIn = ''; % set parameter for seperating values
headerlinesIn = 1; %which line is header
[A] = importdata (filename);
I = A.data (:,:);
X1 = II(:,1); %define X1
Y1 = II(:,2); % define Y1
X2 = II(:,3); %define X2
Y2 = II(:,4); %define Y2
for k = 1: numel (Imfiles(1:2))
fileNames = Imfiles(k).name;
imIndexed = imread (fileNames);
Z1 = impixel (imIndexed(:,:,3), X1,Y1);
Z2 = impixel (imIndexed(:,:,3), X2,Y2);
end
由于我没有你的完整代码,我只能假设一些关于正在发生的事情,而不能实际尝试这个解决方案来看看它是否能满足你的要求。首先,我不确定 impixel 是否应该支持仅传递您使用 imIndexed(:,:,3)
处理的每个像素的第三个元素,而是您应该在使用 impixel 后获得第三个元素。尝试做这样的事情:
for k = 1: numel (Imfiles(1:2))
fileNames = Imfiles(k).name;
imIndexed = imread (fileNames);
tmp1 = impixel (imIndexed, X1,Y1);
tmp2 = impixel (imIndexed, X2,Y2);
Z1 = tmp1(3);
Z2 = tmp2(3);
end
根据@mike Thomson 的建议,我将我的代码修改如下:
filename = 'realworldCoordinates.txt'; % define the file name
delimiterIn = ''; % set parameter for seperating values
headerlinesIn = 1; %which line is header
[A] = importdata (filename);
I = A.data (:,:);
X1 = II(:,1); %define X1
Y1 = II(:,2); % define Y1
X2 = II(:,3); %define X2
Y2 = II(:,4); %define Y2
%loop for reading data from txt file and return the index value
for k = 1: numel (Imfiles(1:2))
fileNames = Imfiles(k).name;
imIndexed = imread (fileNames);
Z1 = impixel (imIndexed(:,:,3), X1(k),Y1(k));
Z1(k,:) =(Z1(:,:,1))
Z2 = impixel (imIndexed(:,:,3), X2(k),Y2(k));
Z2(k,:) =(Z2(:,:,1))
end