problm in imwriting a arrayimage

1 Ansicht (letzte 30 Tage)
rohan
rohan am 4 Mai 2014
Kommentiert: Geoff Hayes am 4 Mai 2014
if true
% code
folder='C:\Users\Public\Videos\Sample Videos\pro\images'; m=0; for k = 1:890 % Get the base file name. baseFileName = sprintf('img%d.jpg', k); % Combine it with the folder to get the full filename. fullFileName = fullfile(folder, baseFileName); % Read the image file into an array. imageArray = imread(fullFileName); a=imageArray; figure(1); imshow(a); title('color image'); c=rgb2gray(a); b=imresize(c, [512 512]); figure(2); imshow(b); title('original gray scale image'); n=512; k=1; for i=1:1:n for j=1:2:n if (j<=n-1) s(i,k)=(b(i,j)+b(i,j+1))/2; d(i,k)=b(i,j)-b(i,j+1); end k=k+1; end k=1; end for i=1:1:n for j=1:1:n/2 b(i,j)=s(i,j); b(i,j+n/2)=d(i,j); end end for j=1:1:n/2 for i=1:2:n if i<=n-1 s(k,j)=(b(i,j)+b(i+1,j))/2; d(k,j)=b(i,j)-b(i+1,j); end k=k+1; end k=1; end for i=1:1:n/2 for j=1:1:n/2 b(i,j)=s(i,j); b(i+n/2,j)=d(i,j); end end figure(3); imshow(b); title('image after one level of compression') for i=1:1:n/2 for j=1:2:n/2 if (j<=n/2-1) s(i,k)=(b(i,j)+b(i,j+1))/2; d(i,k)=b(i,j)-b(i,j+1); end k=k+1; end k=1; end for i=1:1:n/2 for j=1:1:n/4 b(i,j)=s(i,j); b(i,j+n/4)=d(i,j); end end for j=1:1:n/4 for i=1:2:n/2 if i<=n/2-1 s(k,j)=(b(i,j)+b(i+1,j))/2; d(k,j)=b(i,j)-b(i+1,j); end k=k+1; end k=1; end for i=1:1:n/4 for j=1:1:n/4 b(i,j)=s(i,j); b(i+n/4,j)=d(i,j); end end figure(4); imshow(b); title('image after two level of compression') for i=1:1:n/4 for j=1:2:n/4 if (j<=n/4-1) s(i,k)=(b(i,j)+b(i,j+1))/2; d(i,k)=b(i,j)-b(i,j+1); end k=k+1; end k=1; end for i=1:1:n/4 for j=1:1:n/8 b(i,j)=s(i,j); b(i,j+n/8)=d(i,j); end end for j=1:1:n/8 for i=1:2:n/4 if i<=n/4-1 s(k,j)=(b(i,j)+b(i+1,j)/2); d(k,j)=b(i,j)-b(i+1,j); end k=k+1; end k=1; end for i=1:1:n/8 for j=1:1:n/8 b (i, j)=s(i,j); b (i+n/8, j)=d(i,j); end end b=imcrop(b,[0 0 64 64]); m=k; figure (5); imshow(b); title('image after third level of compression') b=imresize(b, [3456 4608]); imshow(b); format = 'jpg'; str = ['C:\Users\Public\Videos\Sample Videos\pro\Newr\im' num2str(m) '.jpg'] ; imwrite(b,str,format) ; m=m+1; end
end
  2 Kommentare
Geoff Hayes
Geoff Hayes am 4 Mai 2014
Bearbeitet: Geoff Hayes am 4 Mai 2014
rohan - since you attached the code in the final.m attachment, there is no need to paste the same thing in your question (though there do appear to be some difference)…which should be reserved for the actual problem with the imwrite. Please describe the issue and/or error message that is observed when you run the above (or attached) code.
However, since there is only one imwrite command in your code, you should put a breakpoint at this line and observe all inputs to the imwrite function. For example, is the C:\Users\Public\Videos\Sample Videos\pro\Ne\ directory valid on your workstation?
rohan
rohan am 4 Mai 2014
yes the directory is valid..what i find is all d images are compressed bt only a single image is saved...i need to save each and every image

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 4 Mai 2014
rohan - when you step through the attached code, does the following line get called 18 times (I'm guessing this is how many images you are reading in based on the first for loop):
str = ['C:\Users\Public\Videos\Sample Videos\pro\Ne\im' num2str(m) '.jpg'] ;
If this line is invoked for every iteration of k, is it distinct on each iteration? I'm guessing it isn't, and here is why. Your first for loop iterates as:
for k = 1:18
However, there are several instances in the code where you re-use k for other purposes, and set it to 1 and then iterate again:
k=1;
for i=1:1:n
for j=1:2:n
if (j<=n-1)
s(i,k)=(b(i,j)+b(i,j+1))/2;
d(i,k)=b(i,j)-b(i,j+1);
end
k=k+1;
end
k=1;
end
This happens a handful of times including near the end:
for j=1:1:n/8
for i=1:2:n/4
if i<=n/4-1
s(k,j)=(b(i,j)+b(i+1,j)/2);
d(k,j)=b(i,j)-b(i+1,j);
end
k=k+1;
end
k=1;
end
% some stuff and then:
b=imcrop(b,[0 0 64 64]);
m=k;
Note how k is reset to one after every completion of the inner for loop (on i). And then m is initialized to k…which means that m is always one and so probably im1.jpg is the only image ever being saved. (Is that correct?)
To correct this, k should never be modified by any inner loop within the code, just choose some other name for this alternate looping/indexing variable.
  2 Kommentare
rohan
rohan am 4 Mai 2014
thnku for the response sir.the code is running well nw.
sir what i need is to convert dis compressed image into video..is it posssible ..if yes how..
Geoff Hayes
Geoff Hayes am 4 Mai 2014
If you want to take these compressed images and translate their sequence into video, then you may want to check out this link: image sequence to video.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by