Struggling to subtract 2 images
조회 수: 3 (최근 30일)
이전 댓글 표시
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))
답변 (2개)
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.
2) You can also use the matlab code for blur image from this https://www.mathworks.com/matlabcentral/answers/450356-how-can-blur-an-image#:~:text=output%20%3D%20blur(img%2Cw,the%20vicinity%20of%20every%20pixel.
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
댓글 수: 0
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!