im working on the project "image compression using sparse algorithm" as my final project. In that i wrote a program for construction of dictionary using random method as given below , in that i'm getting problem, can anybody please help me....

3 views (last 30 days)
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear all;
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB color demo image.
% folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% baseFileName = 'peppers.png';
% % Get the full filename, with path prepended.
% fullFileName = fullfile(folder, baseFileName);
% if ~exist(fullFileName, 'file')
% % Didn't find it there. Check the search path for it.
% fullFileName = baseFileName; % No path this time.
% if ~exist(fullFileName, 'file')
% % Still didn't find it. Alert user.
% errorMessage = sprintf('Error: %s does not exist.', fullFileName);
% uiwait(warndlg(errorMessage));
% return;
% end
% end
% % Read the image from disk.
[fileName, pathName] = uigetfile('*.tif','Select an Image');
imgFileName = strcat(pathName, '\', fileName);
rgbImage = imread(imgFileName);
rgbImage = imresize(rgbImage,[400 400]);
% Test code if you want to try it with a gray scale image.
% Uncomment line below if you want to see how it works with a gray scale image.
% rgbImage = rgb2gray(rgbImage);
% Display image full screen.
imshow(rgbImage);
% Enlarge figure to full screen.
% set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% drawnow;
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
%==========================================================================
% The first way to divide an image up into blocks is by using mat2cell().
blockSizeR = 10; % Rows in block.
blockSizeC = 10; % Columns in block.
% Figure out the size of each block in rows.
% Most will be blockSizeR but there may be a remainder amount of less than that.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows)];
% Figure out the size of each block in columns.
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols)];
% Create the cell array, ca.
% Each cell (except for the remainder cells at the end of the image)
% in the array contains a blockSizeR by blockSizeC by 3 color array.
% This line is where the image is actually divided up into blocks.
if numberOfColorBands > 1
% It's a color image.
patches = mat2cell(rgbImage, blockVectorR, blockVectorC, numberOfColorBands);
else
patches = mat2cell(rgbImage, blockVectorR, blockVectorC);
end
figure;
% Now display all the blocks.
plotIndex = 1;
numPlotsR = size(patches, 1);
numPlotsC = size(patches, 2);
for r = 1 : numPlotsR
for c = 1 : numPlotsC
fprintf('plotindex = %d, c=%d, r=%d\n', plotIndex, c, r);
% Specify the location for display of the image.
subplot(numPlotsR, numPlotsC, plotIndex);
% Extract the numerical array out of the cell
% just for tutorial purposes.
rgbBlock = patches{r,c};
imshow(rgbBlock); % Could call imshow(ca{r,c}) if you wanted to.
[rowsB columnsB numberOfColorBandsB] = size(rgbBlock);
% Make the caption the block number.
% caption = sprintf('Block #%d of %d\n%d rows by %d columns', ...
% plotIndex, numPlotsR*numPlotsC, rowsB, columnsB);
% title(caption);
drawnow;
% Increment the subplot to the next location.
plotIndex = plotIndex + 1;
end
end
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
drawnow;
dictionary1 = {};
% for i=1:1:size(patches,1)
% for j = 1:size(patches,2)
% mn = mean(mean(patches{i,j}));
% patches{i,j} = patches{i,j} - mn;
% end
% end
dictionary1{1,1} = patches{1,1};
atomno = [1];
sdict = numel(dictionary1);
for i = 1:size(patches,1)
for j = 1:size(patches,2)
if(i==1 && j==1)
dictionary1{1,1} = patches{1,1};
else
for m = 1:sdict
P1 = double(dictionary1{1,m});
P2 = double(patches{i,j});
S(i,j) = similarity1(P1,P2);
if(abs(S(i,j))>0.025)
dictionary1{1,sdict+1} = patches{i,j};
atomno =[atomno;sdict+1];
m = m + 1;
sdict = numel(dictionary1);
else
atomno =[atomno;m];
end
% mnp1 = mean(mean(P1));
% mnp2 = mean(mean(P2));
% if(floor(mnp1)~=floor(mnp2))
% dictionary1{m+1} = patches{i,j};
% atomno =[atomno;m+1];
% m = m + 1;
% else
% atomno =[atomno;m];
% end
break;
end
end
end
end
  5 Comments

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!