image processing command error
4 次查看(过去 30 天)
显示 更早的评论
0 个评论
回答(2 个)
Walter Roberson
2016-1-6
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 个评论
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.
Image Analyst
2016-1-7
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".
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!