Struggling to subtract 2 images

4 visualizaciones (últimos 30 días)
Nicholas Lund
Nicholas Lund el 8 de Jun. de 2020
Respondida: Image Analyst el 12 de Jun. de 2020
This is the code i am trying to run, it runs the blurpic fine but can't get the subtraction to work without "Array dimensions must match for binary array op" and "Error in task3 (line 12), y = (pic) - (blurpic);" not sure what to do now.
clear all
pic = double(imread("IMG_5698.JPG")); % original picture used
s = size(pic);
j = 2:s(1) - 1;
k = 2:s(2) - 1;
blurpic(j,k,:) = (pic(j,k,:) + pic(j - 1,k,:) + pic(j + 1,k,:) + ...
pic(j,k - 1,:) + pic(j,k - 1,:) + pic(j,k + 1,:))/5;
%image(uint8(blurpic))
y = (pic) - (blurpic);
%image(uint8(y))
intensepic = y(1:0.1:end, 1:0.1:end, :);
%image(uint8(intensepic))
output = intensepic + original
image(uint8(output))
  1 comentario
darova
darova el 12 de Jun. de 2020
Try to define your blurpic
blurpic = pic*0;
% code...

Iniciar sesión para comentar.

Respuestas (2)

Umar farooq Mohammad
Umar farooq Mohammad el 10 de Jun. de 2020
As you are trying to create a blurpic using your own defult code where you are calcualting the mean of all nearby surrounding pixels. But according to your code the dimentsions are being reduced.
So i suggest you
1) to change the code inorder to handle the pixels at edges aswell so that you dont have to supress the dimensions to 2:s(1)-1.
3) or else you can create an empty image of the dimensions of original and then add blurred pixels to it so as to work with your code. as follows... ( but i suggest you to use any onne from above two options)
clear all
pic = double(imread("C:\Users\umarf\Downloads\Umar Farooq\Photoes\1.jpg")); % original picture used
s = size(pic);
j = 2:s(1)-1 ;
k = 2:s(2)-1 ;
blurpic = zeros(s);
blurpic(j,k,:) = (pic(j,k,:) + pic(j - 1,k,:) + pic(j + 1,k,:) + pic(j,k - 1,:) + pic(j,k - 1,:) + pic(j,k + 1,:))/5;
%image(uint8(blurpic))
y = (pic) - (blurpic);
-Umar

Image Analyst
Image Analyst el 12 de Jun. de 2020
Try this:
rgbImage = imread('peppers.png');
subplot(2, 1, 1);
imshow(rgbImage);
% Now blur it
kernel = [1, 0, 1; 0, 1, 0; 1, 0, 1];
kernel = kernel / sum(kernel(:)); % Normalize so mean intensity does not change.
blurredPic = imfilter(rgbImage, kernel);
subplot(2, 1, 2);
imshow(blurredPic);
impixelinfo

Categorías

Más información sobre Image Processing Toolbox en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by