Note that there are some explanatory texts on larger screens.

plurals
  1. POMatlab Carving Seam function calling
    primarykey
    data
    text
    <p>I want to do a seam carving in an image using Matlab.</p> <p>If i do it using only scripts and not by calling the function,it works.The problem comes when i make the script as a function and try to call it</p> <p>The code i use</p> <p><strong>Final Script:</strong> Its the script i use to call the function over and over so i get the result</p> <pre><code>clear all; close all; %Image = 'mall.jpg'; Image_Array = imread('mall.jpg'); %We keep the dimension of the image array [Row_Count,Column_Count,Colour] = size(Image_Array); Image = double(Image_Array)/255; Image = rgb2gray(Image); for i = 1 : 10 [Image_Array,Row_Count,Column_Count]=Vertical_Seam(Image_Array,Row_Count,Column_Count); imshow(Image_Array); end </code></pre> <p><strong>Vertical Seam:</strong> its the script i use to do the work of seaming.This is the file i would like to make it a function and call it in the Finalscript but i dont know how(You will notice that i tried to make a fucntion but as it didnt work i put it inside % )</p> <pre><code>%function [Final_Image,Row_Count,Column_Count] = Vertical_Seam(Image_Array,Row_Count,Column_Count) Image_Array = imread('mall.jpg'); %We keep the dimension of the image array [Row_Count,Column_Count,Colour] = size(Image_Array); Image = double(Image_Array)/255; Image = rgb2gray(Image); for repeat = 1 : 10 %Calculate the energy [E_x,E_y] = gradient(Image); Energy = abs(E_x) + abs(E_y); %We run the image and keep the minimum sum-energy in Image_Array Cumulative_Energy = zeros(Row_Count,Column_Count); % i represent rows % j represent columns for i = 1 : Row_Count for j = 1 : Column_Count if i==1 Cumulative_Energy(i,j) = Energy(i,j); elseif i&gt;1 if j==1 temp1 = [Cumulative_Energy(i-1,j),Cumulative_Energy(i-1,j+1)]; Cumulative_Energy(i,j) = Energy(i,j) + min(temp1); elseif j&gt;1 &amp;&amp; j&lt;Column_Count temp2 = [Cumulative_Energy(i-1,j-1),Cumulative_Energy(i-1,j),Cumulative_Energy(i-1,j+1)]; Cumulative_Energy(i,j) = Energy(i,j) + min(temp2); elseif j==Column_Count temp3 = [Cumulative_Energy(i-1,j-1),Cumulative_Energy(i-1,j)]; Cumulative_Energy(i,j) = Energy(i,j) + min(temp3); end end end end %Find the minimum value from last column temp_min = Cumulative_Energy(Row_Count,1); point_min = 1; for j = 2 : Column_Count if Cumulative_Energy(Row_Count,j)&lt;temp_min temp_min = Cumulative_Energy(Row_Count,j); point_min = j; end end %Start from the minimum value from last column and backtrack to find the minimum seam %We need an array to keep minimum energy in every row while %backtracking Keep_Seam = zeros(Row_Count,1); Keep_Seam(Row_Count) = temp_min; %We need also the point of the minimum energy (the number of column) Keep_Point = zeros(Row_Count,1); Keep_Point(Row_Count) = point_min; %Paint the pixel Image_Array = Image_Colouring(Image_Array,Row_Count,point_min); for i = Row_Count : -1 : 1 if i==1 if point_min==1 Tmp1 = [Cumulative_Energy(i,point_min),Cumulative_Energy(i,point_min+1)]; Keep_Seam(i) = min(Tmp1); if min(Tmp1)==Cumulative_Energy(i,point_min) Keep_Point(i) = point_min; else Keep_Point(i) = point_min+1; point_min = point_min+1; end Image_Array = Image_Colouring(Image_Array,i,point_min); elseif point_min==Column_Count Tmp2 = [Cumulative_Energy(i,point_min-1),Cumulative_Energy(i,point_min)]; Keep_Seam(i) = min(Tmp2); if min(Tmp2)==Cumulative_Energy(i,point_min) Keep_Point(i) = point_min; else Keep_Point(i) = point_min-1; point_min = point_min-1; end Image_Array = Image_Colouring(Image_Array,i,point_min); elseif point_min&gt;1 &amp;&amp; point_min&lt;Column_Count Tmp3 = [Cumulative_Energy(i,point_min-1),Cumulative_Energy(i,point_min),Cumulative_Energy(i,point_min+1)]; Keep_Seam(i) = min(Tmp3); if min(Tmp3)==Cumulative_Energy(i,point_min) Keep_Point(i) = point_min; elseif min(Tmp3)==Cumulative_Energy(i,point_min-1) Keep_Point(i) = point_min-1; point_min = point_min-1; elseif min(Tmp3)==Cumulative_Energy(i,point_min+1) Keep_Point(i) = point_min+1; point_min = point_min+1; end Image_Array = Image_Colouring(Image_Array,i,point_min); end elseif i==Row_Count || i&lt;Row_Count if point_min==1 Temp1 = [Cumulative_Energy(i-1,point_min),Cumulative_Energy(i-1,point_min+1)]; Keep_Seam(i) = min(Temp1); if min(Temp1)== Cumulative_Energy(i-1,point_min) Keep_Point(i) = point_min; else Keep_Point(i) = point_min+1; point_min = point_min+1; end Image_Array = Image_Colouring(Image_Array,i,point_min); elseif point_min==Column_Count Temp2 = [Cumulative_Energy(i-1,point_min-1),Cumulative_Energy(i-1,point_min)]; Keep_Seam(i) = min(Temp2); if min(Temp2)==Cumulative_Energy(i-1,point_min) Keep_Point(i) = point_min; else Keep_Point(i) = point_min-1; point_min = point_min-1; end Image_Array = Image_Colouring(Image_Array,i,point_min); elseif point_min&gt;1 &amp;&amp; point_min&lt;Column_Count Temp3 = [Cumulative_Energy(i-1,point_min-1),Cumulative_Energy(i-1,point_min),Cumulative_Energy(i-1,point_min+1)]; Keep_Seam(i) = min(Temp3); if min(Temp3)==Cumulative_Energy(i-1,point_min) Keep_Point(i) = point_min; elseif min(Temp3)==Cumulative_Energy(i-1,point_min-1) Keep_Point(i) = point_min-1; point_min = point_min-1; elseif min(Temp3)==Cumulative_Energy(i-1,point_min+1) Keep_Point(i) = point_min+1; point_min = point_min+1; end Image_Array = Image_Colouring(Image_Array,i,point_min); end end end imshow(Image_Array); Image_Seam = zeros(Row_Count,Column_Count-1,Colour,'uint8'); for i = 1 : Row_Count Image_Seam(i,:,:)=Image_Array(i,[1:Keep_Point(i)-1,Keep_Point(i)+1:Column_Count],:); end %imshow(Image_Seam); Image_Array = Image_Seam; end % end </code></pre> <p>I would like to connect those two files so the Finalscript will call the Verticalseam as function and not as a script</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload