Google Groups unterstützt keine neuen Usenet-Beiträge oder ‑Abos mehr. Bisherige Inhalte sind weiterhin sichtbar.

Use Blockproc to do something other than give me a manipulated image

76 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Julia Weidner

ungelesen,
28.07.2010, 13:34:3728.07.10
an
I am working with very large image in matlab so they can't be completely loaded into the working memory of matlab. I started messing around with blockproc but have found that it is very limited in its use since it calls an anonymous function and only returns an image to the workspace.

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!

Walter Roberson

ungelesen,
28.07.2010, 14:29:3528.07.10
an
Julia Weidner wrote:

> 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 ?

ImageAnalyst

ungelesen,
28.07.2010, 15:17:0928.07.10
an
Like Walter said, histogramming can get tricky if it's not uint8. (I
have demos for other data types if needed.)

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().

Walter Roberson

ungelesen,
28.07.2010, 15:30:1728.07.10
an

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 ;-)

Julia Weidner

ungelesen,
28.07.2010, 16:12:1928.07.10
an
Walter Roberson <robe...@hushmail.com> wrote in message <i2q0nv$rqb$1...@canopus.cc.umanitoba.ca>...

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...

Ashish Uthama

ungelesen,
28.07.2010, 16:41:4628.07.10
an
Julia,

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.

0 neue Nachrichten