image processing command error

回答 (2 件)

Walter Roberson
Walter Roberson 2016 年 1 月 6 日

0 投票

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 件のコメント

matlabgeek
matlabgeek 2016 年 1 月 6 日
編集済み: Walter Roberson 2016 年 1 月 8 日
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
Walter Roberson
Walter Roberson 2016 年 1 月 6 日
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.
matlabgeek
matlabgeek 2016 年 1 月 8 日
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.

サインインしてコメントする。

Image Analyst
Image Analyst 2016 年 1 月 7 日

0 投票

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 ExchangeImage Processing Toolbox についてさらに検索

質問済み:

2016 年 1 月 6 日

編集済み:

2016 年 2 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by