how to save many image into mat file??

i have trouble to save all images pixel into mat file. the number of image according to looping k, this is the code:
for k = 1 : y * x % Loop through all character
thisCharsBoundingBox = Iprops(k).BoundingBox; %Get list of pixels in current character.
subImage = imcrop(skeleton2, thisCharsBoundingBox);
imsize=imresize(subImage, [20 20]);%images size be 20x20 pixel
subplot(12, 8, k, 'Parent',handles.panel_pattern,'Position',[1 1 1 1]); %show the image in panel
imshow(imsize);
save image imsize;
end
it just save one images pixel., can anyone help me to solve this trouble...

4 Comments

Any reason why you're not using imwrite() to save it as a regular image format file?
i'm sorry sir.., i don't see your comment ..
not use imwrite() because i want save the pixel value of image., i don't know how to use imwrite() to save the pixel value of image..
To get the pixel values, just imread() the saved image.
imwrite DOES save the pixel values of the image. Maybe you just need to cast your subimage from logical to uint8 before you call imwrite. Then like Walter says, simply use imread to read the image back in from disk. Don't worry, it will have the correct values.

Sign in to comment.

 Accepted Answer

2 Comments

great..., i've found the right solution from http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F.,
its like in your comment,
myfilename = strcat('image', num2str(k), '.mat');
save (myfilename,'imsize');
thanks a lot..:),
can you help me again,
the size of image is too large to used, that is 20rows and 20 columns, i want divide each image to 16 subimage, each subimage size is 5x5. I will count the means value of each subimage to get the new pixel value of image, the new image size is 4rows and 4 columns..
i dont know the right way.., please help me....
Again "Any reason why you're not using imwrite() to save it as a regular image format file?"

Sign in to comment.

More Answers (1)

Regarding your comment about getting the mean in blocks, it might be a little advanced, but would you consider doing it in just 2 or 3 lines (or even 1 if you combine them) by using blockproc()? Here's a full-blown demo - don't be afraid the main part is only 2 lines in the middle, the rest is just tutorial stuff.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Create sample image.
grayImage = uint8(255*rand(20,20));
[rows columns numberOfColorChannels] = size(grayImage);
% Display the original image.
subplot(1, 2, 1);
imshow(grayImage, []);
caption = sprintf('Original Image\n%d by %d pixels', ...
rows, columns);
title(caption, 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
set(gcf, 'name','Demo by ImageAnalyst', 'numbertitle','off')
% Now let's use an anonymous function and the blockproc function.
% This is the real meat of the program, these 3 lines.
% We'll take the mean in the 5 by 5 blocks and get out a 4 by 4 image.
windowSize = 5;
myFilterHandle = @(block_struct) mean2(block_struct.data);
blockyImageMean = blockproc(grayImage, [windowSize windowSize], myFilterHandle);
% Done! Now let's display it.
subplot(1, 2, 2);
imshow(blockyImageMean, []);
[rowsMean columnsMean numberOfColorChannelsMean] = size(blockyImageMean);
caption = sprintf('Image Processed in %d by %d Blocks\nWith an Anonymous Mean Filter\nto produce an image %d by %d pixels', ...
windowSize, windowSize, rowsMean, columnsMean);
title(caption, 'FontSize', fontSize);
msgbox('Done with demo!');

6 Comments

thanks sir.., but function blockprock none in matlab R2008b, can be change to the other function?
You can adapt it. I think in old versions it was called blkproc or something similar.
well, i will try.. thank u so much sir^^..
i have another problem., i use two figure which link one to another fig. In fig 1, there save function., in fig 2 i want use load data where i have saved in fig 1. here's the code:
for k=1:y*x
myfilename = sprintf('image%d.mat', k);
data=load (myfilename);
end
certainly, it was error cause variable y and x undefined in fig2. variable y and x have definition in fig 1., i don't know how to use that variable in fig 2.. any idea?
i can use blkproc in matlab R2008b, thanks Image Analyst..
i hope your help again to solve trouble that i say on previously comment..please!
Is this a simple script, or a program with functions? If you have functions, then your x and y probably aren't seen in some other function than where you first used it. See the FAQ for how to get your x and y to be seen where you need them to be seen. http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
If you have a simple script, then I don't see any reason why x and y aren't seen everywhere in your script, unless you cleared them.
program with functions., thanks for the link, i can solve it., just use setappdata and getappdata function..

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!