Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Looking for help in matlab

Status
Not open for further replies.

shaikh105

Member level 1
Joined
Jul 3, 2007
Messages
35
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,572
matlab using graythresh

Here is a matlab code i am using for ecg image analysis. actually i am capturing an image named s2.png in 1D;
i have 10 images like s1,s2,,,,,,,,,s10,.............or more
if i wanna read all of them at once not one by one and then find the program processed output plot of all those 10 images at once. can anybody help.
the code below is processing only s2.png but to process remaining i have to change s2 to s3 or so and then run the code again. i want to process all 10 images at once how can i do that with this code


clear
[I,map]=imread('s2.png');
j=im2double(I);
level=graythresh(j); % finding threshold using 'otsu method'
k=im2bw(j,level);
[M,N]=size(k);
z=1;
xx=zeros([N,1]);
yy=zeros([N,1]);
for y= 1:N
for x= 1:M
if k(x,y)==0
xx(z)=x;
yy(z)=y;
z=z+1;
end
end
end
t=mean(xx);
ecg=-xx+t;
plot(yy,ecg)
 

Why don't you load each image into an array of 3 dimensions, the 3rd dimension being each image.

Code:
for n = firstFile : 1 : lastFile
number = num2str(n);
        fileI = strcat('I5p0percent00',number,'.txt');
        fileQ = strcat('Q5p0percent00',number,'.txt');
        storedI(:,:,n+1) = (load(fileI)-(darkI/100));
        storedQ(:,:,n+1) = (load(fileQ)-(darkQ/100));

end

I used this for doing something similar.
 

Dear Nick
i am not getting this code and am stuck plz insert this code into my code so that i can get it or plz guide me some other way about this part of code... plus i dont get this 3 dimension array concept.

Regards
 

U can try forming a matrix

U read the images ... convert them to vectors as per ur need

Process them together and reassemble into images

I have done this for my face recognition project

Actually it would be better if u describe your needs and what actually your algorithm or project is
 

Dear Friend u can see my code on the top in this conversation . Mr. Nick gave me a solution , i am not able to incorporate that into my code. i request for help me incorporate this code into my code. i am not understanding how i can convert my vector into a 3 dimensional array as said by Mr. Nick.i hope u got my point.
as far as i got from ur point of view ,,,,,,,,by writing that way u suggested i think it will increase the code processing time.
i mean, if i am right, if i put
I=imread('s1')
{my code}
plot(output of code)
j=imread('s2')
{my code}
plot(output of code)
and so on
this will increase the code processing time
i need a smart code to help me resolve my problem
 

I'm a sorry that I couldn't upload for you the M file now but I can explain to you the function now then I will upload the file for you as soon as I can.
there is a function in matlab named Filename from this functoin you can combine letters with variables tha contain char. e.g( x='s') using the function you can compine
's',x,'.png'
and let x at first equal 1
then x=x+1

Added after 3 minutes:

you can either wait for me to upload the file or you can search in the help of the matlab for filename function
 

Code:
clear 
[I,map]=imread('s2.png'); 
j=im2double(I); 
level=graythresh(j); % finding threshold using 'otsu method' 
k=im2bw(j,level); 
[M,N]=size(k); 
z=1; 
xx=zeros([N,1]); 
yy=zeros([N,1]); 
for y= 1:N 
for x= 1:M 
if k(x,y)==0 
xx(z)=x; 
yy(z)=y; 
z=z+1; 
end 
end 
end 
t=mean(xx); 
ecg=-xx+t; 
plot(yy,ecg)

I'm not going to rewrite the whole thing for you as I don't have your files or the time to work out what sort of processing you are doing ,but i'll show you how to create a 3d matrix for the images to be loaded into,

we'll call the array j.

so j:),:,n+1) addresses the 3rd dimension of sD array j.
so you want to load files named
s0.png s1.png, s2.png, s2.png, etc
so create a loop like so,

Code:
for n = firstFile : 1 : lastFile

create a string for the number in the filename like so

Code:
number = num2str(n);
fileName = strcat('s',number,'.png');

then load the file into the array

Code:
j(:,:,n) = imread(fileName);

so your loop would look like this
Code:
firstFile = 0;
lastFile = 99;

for n = firstFile : 1 : lastFile
   number = num2str(n);
   fileName = strcat('s',number,'.png');
   j(:,:,n) = imread(fileName); //i'm not sure if imread can be used in this way, you may have to use load. I haven't tried it.
end
You now have a 3d array, the individual images are indexed as the 3rd dimension of the array. You can then compare them in parallel, utilising loops instead of having to modify the file and rerun it for every different image.

It depends what you want to do with the loaded image, but you can still use your entire current code in a loop, just replace the s2.png part with the string like I've shown you. That may be easier, since your doing stuff with transparent pixels (or something). Rename anything else you don't want overwritten each loop in the same way.

And indent your code so that it is a bit more readable, it'll make life easier for yourself aswell as others who read it.

Cheers

Code:
firstFile = 0;
lastFile = 99;

for n = firstFile : 1 : lastFile
   number = num2str(n);
   fileName = strcat('s',number,'.png');
   [I,map]=imread(filename);
   j(:,:,n) =  I;%this may do exactly what you're looking for.
% I haven't tried it, but give it a go, and have a play with it and you'll get it!
end
 

hi,
i want MATLAB code for overlap-save method, used for fast convolution. please guide me. help me. thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top