image processing command error

回答(2 个)

What was the error message you received? What MATLAB version are you running? Do you have a license for the Image Processing Toolbox? Is your data 2 dimensional or 3 dimensional?
My speculation is that you are passing an RGB image in. You need to pass either a grayscale image or else one single plane of an RGB image.

3 个评论

Error is attached:
BLOCKPROC encountered an error while evaluating the user-supplied function handle, FUN.
The cause of the error was:
Error using *
Inputs must be 2-D, or at least one input must be scalar.
To compute elementwise TIMES, use TIMES (.*) instead.
Error in @(block_struct)T*block_struct.data*T'
Error in blockprocFunDispatcher (line 13)
output_block = fun(block_struct);
Error in blockprocInMemory (line 80)
[ul_output fun_nargout] = blockprocFunDispatcher(fun,block_struct,...
Error in blockproc (line 236)
result_image = blockprocInMemory(source,fun,options);
I use matlab 2015b
I have license for image processing toolbox
How can I get the grayscale image or else one single plane of an RGB image? Could you please teach me where to get this kind of image?
Thank you a lot
You can use rgb2gray() to transform an RGB image to a grayscale image.
If you have an RGB image array, say MyImage, then MyImage(:,:,1) is the Red components, MyImage(:,:,2) is the Green components, and MyImage(:,:,3) is the Blue components.
I check the reason as below:
"The error is caused by the incompatibility of your block size and image size. As it is suggested in the example, the block size should be 8 by 8 or 16 by 16. In either case, you image size should be multiples of the block size."
Thank you very much for your answer.

请先登录,再进行评论。

You did not follow this code from that page link you gave us:
I = imread('cameraman.tif');
I = im2double(I);
T = dctmtx(8);
dct = @(block_struct) T * block_struct.data * T';
B = blockproc(I,[8 8],dct);
mask = [1 1 1 1 0 0 0 0
1 1 1 0 0 0 0 0
1 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0];
B2 = blockproc(B,[8 8],@(block_struct) mask .* block_struct.data);
invdct = @(block_struct) T' * block_struct.data * T;
I2 = blockproc(B2,[8 8],invdct);
imshow(I), figure, imshow(I2)
It runs fine, though if I had written it, I would have used more descriptive variable names and used subplot. Anyway, you must have altered it somehow but either forgot to tell us how, or don't want to tell us how. So we can only guess and I think Walter's guess that you read in a color image is a good one.
To get a gray scale image, you can do this:
grayImage = rgb2gray(I);
or you can use one of the color channels, which can be extracted like this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
Then use one of those variables instead of "I".

类别

帮助中心File Exchange 中查找有关 Image Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by