image processing command error

4 views (last 30 days)
matlabgeek
matlabgeek on 6 Jan 2016
Edited: matlabgeek on 11 Feb 2016

Answers (2)

Walter Roberson
Walter Roberson on 6 Jan 2016
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 Comments
Walter Roberson
Walter Roberson on 6 Jan 2016
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 on 8 Jan 2016
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.

Sign in to comment.


Image Analyst
Image Analyst on 7 Jan 2016
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".

Community Treasure Hunt

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

Start Hunting!