Why do i get an error when rgb image (tiff) is converted to grayscale ? The value of such image in workspcespace is like <556x663x4 uint8>. Rgb handles only images of type <556x663x3 uint8>.

2 views (last 30 days)
I am doing a project in which the grayscale value for a particular set of image is calculated. In an image(tiff format), there six sub images which are obtained by cropping the original image in microsoft office. After cropping during the processing of these six images, I face the issue of that some of the images not being read by matlab because of value of image is 556x663x4 uint8. The image being read are of the type 556x663x3 uint8. So, I want to know whether the issue is with cropping of tiff or with something else. THanks in advance.
  4 Comments
Sumit Chaudhary
Sumit Chaudhary on 26 Apr 2017
Thanks for the suggestion. In the zip file, I have included the original image with six sub images and code for gray-scale value.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 26 Apr 2017
Edited: KSSV on 26 Apr 2017
You can crop the image in MATLAB itself and do what you want. Check the below code.
I = imread('original.tif') ; % your original image
av = zeros(1,6) ;
for i = 1:6 % loop for each block
imshow(I) ;
[Image, rect] = imcrop(I); % select the image you want by dragging a rectangle
imwrite(Image,strcat(num2str(i),'.tif')) ; % save the cropped image
[pixelCount, grayLevels] = imhist(Image);
bar(grayLevels, pixelCount);
grid on;
av(i) = mean2(Image);
end

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!