The following code, for example, would return a variable "image" to the workspace and then you would have to write this image to a folder:
image=blockproc('image1.tif', [10 10], @(block_struct) imresize(block_struct.data, .5))
The images I am working with are so large that I can't create an "image" variable to put in my workspace and I just save the processed image directly to a destination:
blockproc('image1.tif', [10 10], @(block_struct) imresize(block_struct.data, .5), 'Destination', 'newimage.tif')
I have successfully saved my newimage to a folder in my directory but now I want to know other things about my picture (like the average RGB values) but all blockproc does is save an image. What if I wanted to create a hsitogram of Red values for the image? How would I go about doing this?! Thanks in advance!
> blockproc('image1.tif', [10 10], @(block_struct)
> imresize(block_struct.data, .5), 'Destination', 'newimage.tif')
> I have successfully saved my newimage to a folder in my directory but
> now I want to know other things about my picture (like the average RGB
> values) but all blockproc does is save an image. What if I wanted to
> create a hsitogram of Red values for the image? How would I go about
> doing this?!
I am not clear from your question as to whether you want to apply those to the
old image or to the processed image?
If your blocks are all the same size and you do not have any 0 padding
happening, then
To find average RGB values,
T = blockproc(TheImageFile, [10 10], @(v) mean(reshape(v.data,[],3)));
and then (I speculate here),
mean([ reshape(T(:,1:3:end),[],1), ...
reshape(T(:,2:3:end),[],1), ...
reshape(T(:,3:3:end),[],1) ])
This is speculation because I do not have a release new enough to support
blockproc, so I do not know the exact format that would be returned from the
call. It is also speculation that specifying the blocksize as [10 10] will
give you a 10 x 10 x 3 matrix of RGB values.
Histogramming... more tricky. Are the RGB values in the range [0,1] or are
they uint8 or uint16 ?
What you might try is to save the histograms of each block, and add
them into the "cumulative" histograms, which you're building up for
the entire image, using the "persistent" or "global" keywords, or
getappdata() and setappdata().
Perhaps,
%MaxValue would be 1 or intmax(class(TheImageName))
RGBSelect = 1;
binedges = linspace(0,MaxValue,NumBins);
T = blockproc(TheImageName, [10 10],
@(v)histc(reshape(v.data(:,:,RGBSelect),1,[]),binedges) );
thehistogram = sum( reshape(T .', NumBins, []), 2 ) .';
Except that I would use a block size bigger than 10 x 10 for efficiency.
Oh, and be warned that if the original image could not be duplicated because
doing so would overflow memory, then the above will almost certainly overfill
memory... unless, that is, you use a block size that has more pixels than the
number of bins you are accumulating into.
You want efficiency, you don't use blockproc ;-)
The images I am trying to histogram are uint8. I have tried using global variables but with no avail.
I understand the suggestions on code above but I am curious to your suggestions about how you would go about doing large image processing WITHOUT using blockproc...
Here is a very relevant demo :)
http://www.mathworks.com/products/image/demos.html?file=/products/demos/shipping/images/ipexblockprocstats.html
It is a bit more involved that a function handle, but it should either
give you ideas to do large data processing yourself. Or at least a
template for you to copy to create the histogram.