MATLAB I have this code so far, the object of the assignment is to take the imag
ID: 3588198 • Letter: M
Question
MATLAB
I have this code so far, the object of the assignment is to take the image "Parkes.png", resize it and turn it into four images in a sort of four-square type box. One is supposed to be gray, one is supposed to be gray-from-mean, and one is supposed to be edges, the last is the original image.
The issue I'm having is with concatenation, I'm not sure how to specify the dimensions for concatenation with the different filters on these images. This is the error message I'm receiving:
Error using horzcat
Dimensions of matrices being concatenated are not consistent.
Error in test (line 17)
imshow([F1,F2])
Please note, I am supposed to achieve this using concatenation, not subplot. The images are supposed to be in a 2x2 style setup, with touching edges, like shown below. My code all seems to work until the concatenation at the end, I am unsure of how to set the boundaries so that they work for concatenation.
My code is as follows:
O =imread('Parkes.png');
R = imresize(O,0.25);
%RGB
I1 = R;
%gray
I3 = rgb2gray(R);
%edge
I4 = edge(I3,'sobel');
I4 = uint8(I4.*255);
%gray from mean
I2 = mean(R,3);
I2 = uint8(I2);
F1 = cat(3,I1,I2);
F2 = cat(2,I3,I4);
imshow([F1,F2])
imshow([I1,I2,I3,I4])
Explanation / Answer
O =imread('emma.jpg');
R = imresize(O,0.25);
%RGB
I1 = R;
[r,c,q]=size(R);% R consists of r*c*3 (RGB)
I3=zeros(r,c,3);
t3 = rgb2gray(R);% t3 is r*c*1, grayscale
%converting it to r*c*3
for m=1:r
for n=1:c
I3(m,n,1)=t3(m,n);
I3(m,n,2)=t3(m,n);
I3(m,n,3)=t3(m,n);
end
end
I4=zeros(r,c,3);
t4 = edge(t,'sobel');
t4 = uint8(t4.*255);% t4 is r*c*1
%converting it to r*c*3
for m=1:r
for n=1:c
I4(m,n,1)=t4(m,n);
I4(m,n,2)=t4(m,n);
I4(m,n,3)=t4(m,n);
end
end
%gray from mean
I2=zeros(r,c,3);
t2 = mean(R,3);
t2 = uint8(t2);% t2 is r*c*1
%converting it to r*c*3
for m=1:r
for n=1:c
I2(m,n,1)=t2(m,n);
I2(m,n,2)=t2(m,n);
I2(m,n,3)=t2(m,n);
end
end
%figure,imshow(uint8(I1));
%figure,imshow(uint8(I2));
%figure,imshow(uint8(I3));
%figure,imshow(uint8(I4));
% before, I2,I3,I4 were r*c*1 and I1 was r*c*3, that's why, they could not
% be concatenated (different dimensions)
F1 = cat(2,I1,I2);%horizontal concatenation
F2 = cat(2,I3,I4);%horizontal concatenation
F=cat(1,F1,F2);%vertical concatenation
imshow(uint8(F));
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.