How to select different data points in different images in a loop?

1 vue (au cours des 30 derniers jours)
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 commentaires
KALYAN ACHARJYA
KALYAN ACHARJYA le 12 Jan 2020
Modifié(e) : KALYAN ACHARJYA le 12 Jan 2020
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:
Muhammad Ahmad Seemab Khan
Modifié(e) : Muhammad Ahmad Seemab Khan le 12 Jan 2020
@Kaylan Acharjya
Q1: Yes I have successfully called images.
Q2: Yes they are all the same size.
Q3:
I dont understand what you mean for Q3. But I am trying to select data points one by one for each image from image 1 to image 925. Now lets say I want to select 3 points in image 1. This means 3 values are stored in column 1 of i and j variables. But now MATLAB will only let me select 3 points for rest of the images as well. Is there a way to select, lets say, 4 points in image 2 without getting the error mentioned above?

Connectez-vous pour commenter.

Réponse acceptée

Thiago Henrique Gomes Lobato
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 commentaires
Thiago Henrique Gomes Lobato
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.
Muhammad Ahmad Seemab Khan
You are right! That was my mistake, I'm sorry. Thanks a lot for your help!!!!!

Connectez-vous pour commenter.

Plus de réponses (1)

KALYAN ACHARJYA
KALYAN ACHARJYA le 12 Jan 2020
Modifié(e) : KALYAN ACHARJYA le 12 Jan 2020
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
  1 commentaire
Muhammad Ahmad Seemab Khan
I need to be able to physically select the points on the image. Like the image pops up and I select points on the image. I'm not sure if this code will let me do that?

Connectez-vous pour commenter.

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by