Matlab source code for Image compression algorithm

I need a source code for image compression algorithm that will read the image and then compress it and save it in another folder. There is no need to display the image while executing. It would be more helpful if the source code works on multiple files through a loop. p.s i am working in matlab 2010a

 Accepted Answer

originalImage = imread(inputfilename);
[inputFolder, baseFileName, ext] = fileparts(inputfilename);
% Write as compressed JPG or PNG or whatever.
outputFileName = fullfile(outputFolder, [baseFileName, '.jpg']);
imwrite(originalImage, outputFileName);

13 Comments

I need the source code for compressing the jpg
I don't have it, other than a call to imwrite(). Have you tried the internet or the OpenCV library?
Requiring source code for jpg is usually due to having been given an assignment to use DCT to compress images. We often get students asking for the code for that. Few of the volunteers will give out the code for non-trivial work like that.
I need the source code for compressing the jpg
Then search for it in the Answers system. People have posted multiple versions of it.
But remember that the people who mark your assignments have access to the same postings to check for plagiarism.
I want code to view compressed image
You have to decompress it first. imread() will decompress some formats such as PNG or JPG. If you've used some custom, non-standard format then you need to decompress it yourself. Then use imread() to view it:
img = imread(fileName);
imshow(img);
can you please give us full code
@Nakshatra who are you talking to? Full code for what? There is code above. What other code do you want? What would it do that the above code is not doing?
Nakshatra, you are asking for code for some program. What are you hoping the program will do? We have been discussing several different programs, and we do not know which one you are interested in.
if you be exist to the code ,can you sent to me because i need it and doesn't reach for any code
doaa, we have been discussing multiple programs, and we do not know which one you want.

More Answers (2)

Well Steven Lord,
I have tried to write a code myself.
Please try to assist me here.
clc;
clear all;
close all;
a = imread("location");
ag = rgb2gray(a);
imshow(a)
z = zeros(size(ag));
[x y] = size(ag);
for i = 1:x
z(i,1) = ag(i,1);
for j = 2:y
z(i,j) = ag(i,j-1) - ag(i,j);
end
end
disp(z)
figure()
imshow(z)

1 Comment

That code does no image compression. It tries to find the difference between adjacent pixels, perhaps in preparation for delta encoding. However, you will find that ag is likely uint8 and when you subtract a larger uint8 from a smaller you get 0 rather than negative. If you were to take care to double(ag) then you could get negative. However you are storing the results in double() and imshow of double with negative values might not give you the results you expect. Does it make sense to display the difference between adjacent pixels as if it were itself an image?
By the way: read about diff()
Hi i need source code for DNA comprission by using huffman algorithm

6 Comments

Finding a consultant to hire and negotiating payments could take several days. It would probably be faster for you to just write the program yourself.
thanks a lot i have question. how i can enter my inputs like probability and symbole from datasets
and how can i apply this code on DNA from datasets, is it manoualy or there is command to do that, my problem is how i can find and enter datasets for huffman code.
huffmandict() can calculate probabilities.
You can probably created a datastore object and use a small loop to process the entires. See https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.read.html
hi i need code to do this,Give an example of image compression using MATLAB code.
@mousa just save your image variable as a JPG or PNG image file
imwrite(rgbImage, 'compressed image.jpg'); % Lossy compression
imwrite(rgbImage, 'compressed image.png'); % Lossless compression

This question is locked.

Categories

Asked:

on 16 Mar 2014

Locked:

on 30 Jul 2024

Community Treasure Hunt

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

Start Hunting!