% Image Arithmetic Operations
% Image addition is done between two similar size of image, so image resize
% function is used to make size of both image same.
% I=I1+I2
clc
close all
I1=imread('test.jpg');
I2=imread('test_1.jpg');
subplot(2,2,1);imshow(I1);title('Original image I1');
subplot(2,2,2);imshow(I2);title('Original image I2');
I=I1+I2; % Addition of two images
subplot(2,2,3);imshow(I);title('Addition of image I1+I2');
I=I1-I2; % Subtraction of two images
subplot(2,2,4);imshow(I);title('Subtraction of image I1-I2');
figure;
subplot(2,2,1);imshow(I1);title('Original image I1');
I=I1+50;
subplot(2,2,2);imshow(I);title('Bright image I');
I=I1-100;
subplot(2,2,3);imshow(I);title('Dark image I');
M=imread('key.png');
M=im2bw(M); % Converts into binary image having 0s and 1s
I=uint8(I1).*uint8(M); % Type casting before multiplication
subplot(2,2,4);imshow(I);title('Masked Image I');
%clear all;
[filename,pathname]=uigetfile({'*.bmp;*.jpg;*.gif','Choose Image File'});
myimage=imread(filename);
if(size(myimage,3)==3)
myimage=rgb2gray(myimage);
end
[Rows,Cols]=size(myimage);
newimage=zeros(Rows,Cols);
k=1;
while k<5
for i=1:Rows
for j=1:Cols
if k==1
newimage(i,j)=myimage(i,j)-100;
end
if k==2
newimage(i,j)=myimage(i,j)-50;
end
if k==3
newimage(i,j)=myimage(i,j)+50;
end
if k==4
newimage(i,j)=myimage(i,j)+50;
end
end
end
subplot(2,2,k);imshow(newimage,[]);
k=k+1;
end
% calculate mean value
[Rows,Cols]=size(myimage);
newimage=zeros(Rows,Cols);
total=0;
for i=1:Rows
for j=1:Cols
total=total+myimage(i,j);
end
end
average=total/(Rows*Cols);
我很麻煩,因爲這個錯誤沒有解決,我是新來的matlab編碼,所以請幫助我,你的解決方案將在未來讚賞我。 我遇到了以下提到的錯誤:矩陣尺寸的matlab代碼錯誤
???錯誤使用==>時間矩陣尺寸必須一致。
錯誤==> DIP_3在23 I = uint8(I1)。* uint8(M); %類型轉換之前 乘法
以及錯誤是不言自明的。 'l1'和'M'的大小是不同的。如果你想把它們放在一起,它們必須是相同的。 –
然後告訴我他們的尺寸如何保持相同 –
您的代碼一開始的評論是「圖像添加是在兩個相似尺寸的圖像**之間完成的,因此**圖像尺寸調整功能用於製作尺寸兩者的圖像相同。「 (強調我的。)我沒有看到你調整圖像的大小,以使它們的大小相同。 – beaker