Struggling to subtract 2 images

4 ビュー (過去 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 Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by