Error: Matrix dimensions must agree. How to solve?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
This is my code for a uniform quantizer and I am getting an error for equation ''y''. %Project 2 %Quantization
clc;
close all;
org_image=imread('C:\Users\Aishwarya Kumar\Desktop\lena512.bmp');
subplot(2,2,1);
imshow(imread('lena512.bmp'));
title('Original Image');
org_image=double(org_image);
for x=5:7
level= 2^x;
lev1=256/(level);
[tk,rk]=tk_rk(lev1,level);
%Quantization
for i=1:256
for j=1:256
for k=1:1:(level)
if org_image(i,j)<tk(k+1) && org_image(i,j)>=tk(k)
recon_image(i,j)=rk(k);
end
end
end
end
recon_image=double(recon_image);
y=double(org_image-recon_image);
%MSE Calculation
MSE=sum(sum(power(y,2)))/(256^2);
%PSNR Calculation
PSNR=10*log10((255^2)/MSE);
recon_image=uint8(recon_image);
subplot(2,2,x-3);
imshow(recon_image);
title([num2str(level),' Levels Quantized Image']);
end
%Function definition
function[tk,rk]=tk_rk(level,lev1)
tk(1)=0;
for a=2:1:(lev1+1)
tk(a)=tk(a-1)+level;
end
for a=1:1:(lev1)
rk(a)=tk(a)+level/2;
end
end
3 commentaires
KSSV
le 16 Fév 2018
This line:
y=double(org_image-recon_image);
Your org_image is 512*512 and recon_image is 256*256. How you think you can subtract them?
Réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!