Struggling to subtract 2 images

조회 수: 3 (최근 30일)
Nicholas Lund
Nicholas Lund 2020년 6월 8일
답변: Image Analyst 2020년 6월 12일
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
darova
darova 2020년 6월 12일
Try to define your blurpic
blurpic = pic*0;
% code...

댓글을 달려면 로그인하십시오.

답변 (2개)

Umar farooq Mohammad
Umar farooq Mohammad 2020년 6월 10일
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 2020년 6월 12일
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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by