MATLAB Answers

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

7 views (last 30 days)
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 Comments

KALYAN ACHARJYA
KALYAN ACHARJYA on 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
@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?

Sign in to comment.

Accepted Answer

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 Comments

Muhammad Ahmad Seemab Khan
unfortunately that doesn't work either. With that code, points are not getting saved at all. (see pic)4.JPG
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato on 19 Jan 2020 at 11:00
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
Muhammad Ahmad Seemab Khan on 21 Jan 2020 at 1:47
You are right! That was my mistake, I'm sorry. Thanks a lot for your help!!!!!

Sign in to comment.

More Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 12 Jan 2020
Edited: KALYAN ACHARJYA on 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 Comment

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?

Sign in to comment.

Sign in to answer this question.

Tags

Products


Translated by