combining two of my codes in image processing

2 次查看(过去 30 天)
this is my two code during my project of video compression.. the code given below is for compressing a single image...
a=imread('i:\w.jpg');
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]);
figure (5);
imshow(b);
title('image after third level of compression')
b=imresize(b, [3456 4608]);
imwrite(b,'i:\imageq.jpg');
.............................................................................................
and dis is my code for copyng a series of image and further saving it....
% Define input and output folders. CHANGE THESE!!!!
inputFolder = 'C:\Users\Public\Videos\Sample Videos\pro\New folder\';
outputFolder = 'C:\Users\Public\Videos\Sample Videos\pro\Ne';
% Check to see that they both exist.
if ~isdir(inputFolder)
errorMessage = sprintf('Error: The following input folder does not exist:\n%s', inputFolder);
uiwait(warndlg(errorMessage));
return;
end
if ~isdir(outputFolder)
errorMessage = sprintf('Error: The following output folder does not exist:\n%s', outputFolder);
uiwait(warndlg(errorMessage));
return;
end
% Get a list of files to copy.
filePattern = fullfile(inputFolder, '*.jpg');
fileNamesToTransfer = dir(filePattern);
numFiles = length(fileNamesToTransfer);
% Do the copying.
for k = 1 : numFiles
% Get the base file name.
baseFileName = fileNamesToTransfer(k).name;
% Create the full input and output filenames.
fullInputFileName = fullfile(inputFolder, baseFileName);
fullOutputFileName = fullfile(outputFolder, baseFileName);
fprintf(1, 'Now copying file #%d of %d: %s to %s\n', ...
k, numFiles, fullInputFileName, fullOutputFileName);
copyfile(fullInputFileName, fullOutputFileName);
end
msgbox('Done copy files!', 'modal');
............................................................................................
what do i want is to compress each and every image from the folder and further copy to some other folder.. i m finding myself unable to combine both.... kindly help me with the combined code...

回答(1 个)

Image Analyst
Image Analyst 2014-4-27
In your loop in the second chunk of code, call a function that compresses the image, I guess that's the first chunk of code.
status = CompressAndSaveImage(fullInputFileName, fullOutputFileName);
The CompressAndSaveImage() is probably your fist chunk of code and it would read in the image and save it with the supplied second argument.
  2 个评论
rohan
rohan 2014-5-4
sir i tried the thngs u said..still unsucessfull..can u edit the code and resend me including ur ideas
Image Analyst
Image Analyst 2014-5-4
Why don't you just try saving the array as a PNG image file? That's compressed.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by