saving processed image which is in form of array to another single dimenison array
1 次查看(过去 30 天)
显示 更早的评论
if true
% code
>> folder='C:\Users\Public\Videos\Sample Videos\pro\Ne';
m=0;
for k = 2 : 10
% 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;
g(m)=b;
end
figure (5);
imshow(b);
title('image after third level of compression')
b=imresize(b, [3456 4608]);
end
for n=2:10
imshow(b);
format = 'jpg';
str = ['C:\Users\Public\Videos\Sample Videos\pro\Newr\im' num2str(k) '.jpg'] ;
b=g(n);
imwrite(b,str,format) ;
end
Warning: Image is too big to fit on screen; displaying at 67% > In imuitools\private\initSize at 72 In imshow at 259 In an assignment A(:) = B, the number of elements in A and B must be the same.
>> folder='C:\Users\Public\Videos\Sample Videos\pro\Ne'; m=0; for k = 2 : 10 % 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]); g(k)=b; end figure (5); imshow(b); title('image after third level of compression') b=imresize(b, [3456 4608]); end for n=2:10 imshow(b); format = 'jpg'; str = ['C:\Users\Public\Videos\Sample Videos\pro\Newr\im' num2str(k) '.jpg'] ; b=g(n); imwrite(b,str,format) ; end
.................................................................................................... 'my error is-' > In imuitools\private\initSize at 72 In imshow at 259 In an assignment A(:) = B, the number of elements in A and B must be the same.
end
2 个评论
Image Analyst
2014-4-27
I don't know what to do with that alphabet soup of uncommented code. Read this and then fix your post: http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!