How to select different data points in different images in a loop?
1 次查看(过去 30 天)
显示 更早的评论
Muhammad Ahmad Seemab Khan
2020-1-12
评论: Muhammad Ahmad Seemab Khan
2020-1-21
I wish to select a different number of data points for different image in this loop but I can't do that since it gives me an error "Unable to perform assignment because the size of the left side
is 3-by-1 and the size of the right side is 4-by-1.". Is there a way to make the 3-by-1 to 4-by-1 by adding zeros as needed?
clear
clc
close all
% Read images in order from 1 to 925.
% Files are in the "myFolder" directory.
imageFolder = 'D:\Research File\September 26\C001H001S0001';
for k = 1:925
tifFilename = sprintf('C001H001S0001000%03d.tif', k);
fullFileName = fullfile(imageFolder, tifFilename);
if exist(fullFileName, 'file')
imageData = imread(fullFileName);
Pic=imageData/64;
else
warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
image(Pic);
colormap(bone);
xlabel('$x$','fontsize',24,'interpreter','latex');
ylabel('$y$','fontsize',24,'interpreter','latex');
[i(:,k),j(:,k)]=getpts;
end
2 个评论
KALYAN ACHARJYA
2020-1-12
编辑:KALYAN ACHARJYA
2020-1-12
Make it more simple please, so that the question can be understood easily. As per the description of the questions, the issue is not with images call right.
Q1: As per my understanding you have sucessfully called the images and wish to get the random spatial location from the image??
Ans:: Yes or no
Q2: Are there all images have same size?
Ans:: Yes/No
Q3: As you mentioned about adding zeros, zero padding right, to make image for equal size??
Ans:
采纳的回答
Thiago Henrique Gomes Lobato
2020-1-12
I don't think a zeropad approach would be optimal, the main problem is that your vector can increase size every time as the same time as your inputs can be smaller. To solve this you can use a cell array which can hold different size vectors without problem. This code solves your problem:
clear
clc
close all
% Read images in order from 1 to 925.
% Files are in the "myFolder" directory.
imageFolder = 'D:\Research File\September 26\C001H001S0001';
i = cell(925,1);
j = cell(925,1)
for k = 1:925
tifFilename = sprintf('C001H001S0001000%03d.tif', k);
fullFileName = fullfile(imageFolder, tifFilename);
if exist(fullFileName, 'file')
imageData = imread(fullFileName);
Pic=imageData/64;
else
warningMessage = sprintf('Warning: image file does not exist:\n%s', fullFileName);
uiwait(warndlg(warningMessage));
end
image(Pic);
colormap(bone);
xlabel('$x$','fontsize',24,'interpreter','latex');
ylabel('$y$','fontsize',24,'interpreter','latex');
[i{k},j{k}]=getpts;
end
3 个评论
Thiago Henrique Gomes Lobato
2020-1-19
Could you give me the exact code you're running? i_pts wasn't in your initial code (the size is also different) and I'm pretty sure the result saves in the variable, so probably you have a variable typo somewhere which I can't see without looking at the exact code you're running.
更多回答(1 个)
KALYAN ACHARJYA
2020-1-12
编辑:KALYAN ACHARJYA
2020-1-12
Hope I understand the question??
Yes, lets suppose three data points points in image 1. Please stored in a array or matrix (whatever). Assigned those array data as a cell array elements to store, then only proceeed for next image call operation, is this?
im_data_points={};
for k=
image=imread()
[r c]=size(image);
num_data_points=input('Enter the data Points Required: ');
im_data=[];
iter=1;
while iter<=num_data_points
r_data=randi(r);
c_data=randi(c);
pix_data=image(r_data_c_data);
im_data=[im_data; r_data,c_data,pix_data];
iter=iter+i;
end
im_data_points{k}=im_data
end
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!